I want to do a regex to have a maximum number of 100 with 2 decimals
I made the following regex:
^\d *\,\d{0.2}$
my problem :
I can only put a comma (ex: 100,00) but if I put a dot it does not work (100.00)
i tried to change my regex with ^\d *\,.\d{0.2}$
but i have the same problem
how can I do ?
CodePudding user response:
You may try:
^(?:[1-9]?[0-9]|100)(?:[.,]\d{1,2})?$
This matches a whole number component of between 0 and 100, with optional decimal component.
^
(?:
[1-9]?[0-9] match 0 to 99
| OR
100 match 100
)
(?:[.,]\d{1,2})? match an optional decimal component (1 or 2 digits)
$