I currently have this regular expression for a whole number with optional decimal to 2 places.
I need to chnage it so that the number has to be greater than 1.
Can anyoen help
Code:[0-9]+(\.[0-9][0-9]?)?
Printable View
I currently have this regular expression for a whole number with optional decimal to 2 places.
I need to chnage it so that the number has to be greater than 1.
Can anyoen help
Code:[0-9]+(\.[0-9][0-9]?)?
Hey,
Wouldn't you just change the first 0-9 to be 1-9?
However, what is wrong with using the regular expression to bring out the number, and then doing a normal > operation on the result?
Gary
Hi Gep, Thats the first thing I tried mate but that means no 0's would be allowed before the decimal.
so 12.58 would pass but 10.58 wouldnt.
I wanted to have this all done through the same regular expression validator ideally so I coudl avoid postback.
Possibly something like [1-9][0-9]+(\.[0-9][0-9]?)?
Ah, so you are doing validation on the client...
Couple of options, Range Validator, or a custom validator.
Yes, your last option should do it, or at least get you closer. The only problem being whether you need a number higher than 99?
Gary
Yes it client side, I managed to work it out anyway, and learn something so was quite good.
The ^[1-9]{1} means:Code:^[1-9]{1}([0-9]+)?(\.[0-9][0-9]?)?
^ Start of string
[1-9] character between 1 and 9
{1} Limited to one
Finally I wrapped the [0-9] in () and added ? after which means optional as this isnt mandatory anymore
Good stuff! Yes, regex can be fun :)
A useful site to keep bookmarked is this one:
http://gskinner.com/RegExr/
Gary