How to validate the field to allow only numbers,(comma).(dot) Please suggest if script is needed

Archana23
Tera Contributor

How to validate the field to allow only numbers,(comma).(dot)

Please suggest if script is needed

10 REPLIES 10

Ashish Parab
Mega Sage

Hello @Archana23 , 

Previously, I have given you a solution. Please find below the thread:

https://www.servicenow.com/community/virtual-agent-forum/how-to-make-a-variable-to-be-restricted-lik...

 

Now, if you want to accept a comma in your input, then please use the below regex:

Regex - ^\d{1,3}(,\d{3})*(\.\d{1,2})?$

 

This will accept 1,234,567.89 , 1,234.56 types of numbers. If you want others, please let me know.

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish

It should accept dot,comma, numbers.

After comma or dot it should accept only 2 digits.

Please use the below updated regex:

^\d+(,\d{1,2}|\.\d{1,2})?$

 

This will accept the below inputs. If these are not with your requirement, please share your inputs.

123
123,1
123,12
123.1
123.12

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish

Not working as expected, it is not accepting comma