Reputation: 3963
This is my regex to check percentage with 2 decimals up to 100
^-?(100([.]0{1,2})?)$|(^\d{1,2}([.]\d{1,2})?)
but is working only in 99.16
and not like -99.16
How to allow also minus percentage?
Upvotes: 4
Views: 950
Reputation: 7928
You've just missed the ^-? in the second option
^-?(100([.]0{1,2})?)$|(^-?\d{1,2}([.]\d{1,2})?)
Upvotes: 2
Reputation: 186803
You have two alternatives:
both alternatives can have minus sign (-
):
(^-?(100([.]0{1,2})?)$)|(^-?[0-9]{1,2}([.][0-9]{1,2})?$)
as a remark, you probably want [0-9]
when matching digits not any character treated as digit '\d'
which include, say, Persian digits ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷
Upvotes: 3