The CreatorCon Call for Content is officially open! Get started here.

RegExp help in validating numbers in a string field

Suryansh Verma
Tera Contributor

Hello Community,

 

I have a string field for inputting hours.

 

The field should only allow negative numbers & decimal(.) & also comma(,) for that i am using the below expression.

/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:(\.|,)\d+)?$/

 

now I also want to restrict the decimal places (before and after ) to upto 3 digits only and also 

 

so accepted value should be 
-123.456 or -123,456 and not -1234.5678 or -1234,5678

1 ACCEPTED SOLUTION

Hemant Goldar
Mega Sage

Hi @Suryansh Verma,

 

Please try the below regular expression

 

^-?(?:\d{1,3}(?:,\d{3})*|\d+)([.,]\d{1,3})?$

 

I hope this helps!

 

Regards,

Hemant 

**Please mark my answer correct or helpful based on the impact**

View solution in original post

6 REPLIES 6

@Suryansh Verma here is the regular expression - ^-?\d{1,10}([,.]\d{1,3})?$

@Hemant Goldar Perfect !!!
Thanks for your help.