Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate a percentage to two decimal places with a 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.

like image 963
littlechris Avatar asked Sep 14 '09 14:09

littlechris


1 Answers

In Perl:

/(^100([.]0{1,2})?)$|(^\d{1,2}([.]\d{1,2})?)$/

or you can just add an extra if comparing 100 exactly :)

like image 184
DVK Avatar answered Sep 28 '22 08:09

DVK