Hi All,
I need a help
How to change this regular expression that allows to accept positive numbers
like 0, 0.00, .02,etc.. ,
Now this accept 5 digits decimal that is greater than 0 and up to 100
"^100|(\d\d?)(\.(1[01]?|0\d?))?$"
Hi All,
I need a help
How to change this regular expression that allows to accept positive numbers
like 0, 0.00, .02,etc.. ,
Now this accept 5 digits decimal that is greater than 0 and up to 100
"^100|(\d\d?)(\.(1[01]?|0\d?))?$"
First you should wrap the whole expression except the string boundaries in a group. Otherwise your expression would just say either start with … or end with … as the |
has a higher precedence than ^
and $
:
^(100|(\d\d?)(\.(1[01]?|0\d?))?)$
And now a solution to your question:
^((100|[1-9]?[0-9])(\.\d{1,2})?|\.\d{1,2})$
I am not sure in which language you are wishing to get the result but it seems quite simple. The rules are input should start with either digit(s) or decimal point and then, either decimal point or digit(s).