Reputation: 677
I'm trying to write a regex for a RegularExpressionValidator Control that will allow a decimal or integer with the following conditions:
A solitary zero is allowed
So these are good....
0
0.1
0.12
1.34
12.45
123.67
1234.67
12345.7
and these are bad.....
-0
-0.1
012.4
123.560
123...7
could someone advise on this please. i've had a few attempts and the main component i'm struggling with is checking for just one decimal point. thank you
Upvotes: 2
Views: 1364
Reputation: 425043
Here's another way of doing it, without look-behinds:
^(?=.{1,7}$)(0(?=\.|$)|[1-9])\d*(\.\d?[1-9])?$
See a live demo on rubular
Upvotes: 0
Reputation: 785196
Following regex should work for you:
(?!^0[1-9])(?=^([0-9])+(\.\d{1,2}(?<!0))?$)^.{1,7}$
Upvotes: 2