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?
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?
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 ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷
You've just missed the ^-? in the second option
^-?(100([.]0{1,2})?)$|(^-?\d{1,2}([.]\d{1,2})?)