RegExp to include comma as well

Suryansh Verma
Tera Contributor

I have a client script that allows only (-ve) numbers along with decimal values up to 2 places.

I want to allow users to use commas as well in place of decimal (dot) if they want.

I am using the below expression

var regexp = /^-[1-9][0-9]?(\.[0-9]{1,2})?$/;

How do I modify it so that it also accepts values like (10,11 ) as an alternative to (10.11)

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi

your expression had an error when dealing with the starting "-" sign.

And the full expression is

^[-]?[1-9][0-9]?([\,\.]{1,1}[0-9]{1,2})?$

See https://regex101.com/r/hNF58f/1 if you want to play around

Maik

View solution in original post

2 REPLIES 2

Maik Skoddow
Tera Patron
Tera Patron

Hi

your expression had an error when dealing with the starting "-" sign.

And the full expression is

^[-]?[1-9][0-9]?([\,\.]{1,1}[0-9]{1,2})?$

See https://regex101.com/r/hNF58f/1 if you want to play around

Maik

Thanks @Maik Skoddow  🙂