Reputation: 4261
I have a regex Decimal that accepted only(.) i want to accepted also (,). that meant the user can enter value 0.1 or 0,1
"^[0-9]{1,5}(\.[0-9]{0,2})?$"
how can I modified this regex to accepted , also
Upvotes: 0
Views: 87
Reputation: 39365
Just add the comma and dot inside the character class to handle both []
^[0-9]{1,5}([.,][0-9]{0,2})?$
^
But I am not sure why you are checking {0,2}
at the end? Which means only it will accept 1111.
as a valid input. So better make it {1,2}
Upvotes: 0
Reputation: 12797
Replace \.
by [.,]
. You'll get the following regex
^[0-9]{1,5}([.,][0-9]{0,2})?$
Upvotes: 3