Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression to accept all the decimals from 0 to 100

Tags:

regex

I want to modify my existing Regular Expression which accepts decimals from 0 to 99.99

\d{0,2}(\.\d{1,2})?$ 

i want this to be accept

100
100.0
100.00

and should not accept

100.1
100.02
101

Can anyone help me modify the above RE

like image 948
Ishan Avatar asked Dec 06 '22 13:12

Ishan


1 Answers

I guess it's best to add the test for 100 as a special case using |:

^(\d{0,2}(\.\d{1,2})?|100(\.00?)?)$ 
like image 194
user123444555621 Avatar answered Feb 24 '23 02:02

user123444555621