For angular app,
We need validation like the user can enter between 0-99 and also can enter up to 2 digit decimal points.
For example,
-
0 -> Pass
-
0.1 -> Pass
-
1.12 -> pass
-
12.12 -> Pass
-
100 -> Fail
-
19.111 -> Fail
-
1.-> Fail
^[0-9]+([.][0-9]{1,2})?$
this pattern is working for other cases apart from case( 100 -> Fail)
for that I tried pattern something like ^([0-9]{1,2})+([.][0-9]{1,2})?$
but it’s not working as expected.
Please suggest a pattern that covers all cases.
3
Answers
Made the below pattern with the help of wnvko and Sameshostee answers, it's working properly with this Validators.pattern('...').
Thanks @wnvko and @Sameshostee for your help.
^(?:99|[0-9]{1,2})([.][0-9]{1,2})?$
/^(?:99|d{1,2})(?:.d{1,2})?$/
That should be it, please test it further.
You can go with something like this
Here’s how it works:
This will not match 09