Reputation: 4462
I am facing an issue of matching expected values using regular expressions. My expected minimum value is 0.01 and the maximum value is 15.99.
Regular expression:
^(1[0-5]|0[0-9]|[0-9])(?:\.([0-9]{1,2}))$
Failure scenarios:
0.00
Upvotes: 0
Views: 157
Reputation: 10466
You can try this:
^(?!(0.00|00.00))(1[0-5]|0[0-9]|[0-9])(?:\.([0-9]{1,2}))$
Although it is already accepted, the regex can be simplified a bit by:
^(?!(0.00|00.00))((0\d?|1[0-5]?).\d{1,2})$
Upvotes: 1
Reputation: 817
Just add (?!0.00?)
before your pattern.
^(?!0.00?)(1[0-5]|0[0-9]|[0-9])(?:\.([0-9]{1,2}))$
Upvotes: 1