Is there a regex that would validate a percentage value to 2 decimal places?
I have a regex for two decimal places, but don't know how to stop values above 100. e.g. 100.01 is validated with my regex.
Is there a regex that would validate a percentage value to 2 decimal places?
I have a regex for two decimal places, but don't know how to stop values above 100. e.g. 100.01 is validated with my regex.
In Perl:
/(^100([.]0{1,2})?)$|(^\d{1,2}([.]\d{1,2})?)$/
or you can just add an extra if comparing 100 exactly :)
Try this one:
\d{1,2}\.\d{2}
That gives you a one digit or two digit number followed by exactly two decimal places. If you want to allow tenths as well (ala 10.1) then try this:
\d{1,2}\.\d{1,2}
/^(?:100(?:.0(?:0)?)?|\d{1,2}(?:.\d{1,2})?)$/
Works with:
etc.