I have a requirement to restrict the numbers between 3.00 to 100.00 I used below expression
^([3-9]|[1-9][0-9]|100)+(\.\d{1,2})?$
The issue with above expression is that, it's allowing 100.01 to 100.99,which should be restricted.It also allows 310 to 399,which needs to restricted.
I used another flavor of same expression
^([3-9]|[1-9][0-9]|100.00)+(\.\d{1,2})?$
Which was working as expected,but we need to enter 100.00 in to pass the regular expression instead of 100.
Is there any way,I can achieve the desired result?
When alternating with the final 100, use negative lookahead for \.\d?[1-9], to ensure that the decimal places, if any, have only 0s.
Your first pattern can also match many repeated digits before the optional decimal (like 333 and 101010) due to the + at the end of the group, so best to remove the + if you only want to match between 3 and 100.
^(?:[3-9]|[1-9][0-9]|100(?!\.\d?[1-9]))(?:\.\d{1,2})?$
^^^^^^^^^^^^^^
https://regex101.com/r/tJd3LQ/1
To permit leading zeros, add 0* right after the ^:
^0*(?:[3-9]|[1-9][0-9]|100(?!\.\d?[1-9]))(?:\.\d{1,2})?$
^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With