P
P
proshik2014-02-17 08:39:47
Java
proshik, 2014-02-17 08:39:47

How to write a regular expression for a number?

You need to write a regular expression for a positive number, with or without 2 decimal places. No other characters are allowed, zero cannot be the first character
Example:
12.13 = true
1.12 = true
234234 = true
0213 = false
-234.23 = false
0.12 = false
23-.23 = false
23f = false
Just this: \d+( \.\d{0,2})?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bimeg, 2014-02-17
@proshik

[1-9]\d*?(\.\d{1,2})?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question