I have some client-side validation against a input type number which
I've tried with 2 digit length validation but how can I validate specific list of decimal numbers with regex ?
/^\d{1,2}(\.\d{1,2})?$/
VALID CASES
5.25
78.5
99.75
INVALID CASES
88.12
50.78
You could write the pattern as:
^\d{1,2}\.(?:00|[72]5|33|67|50?)$
Explanation
^
Start of string\d{1,2}
Match 1 or 2 digits\.
Match a dot(?:
Non capture group for the alternatives
00|[72]5|33|67|50?
match 00
75
25
33
67
5
or 50
)
Close the non capture group$
End of string