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

Validation regex for using in client script

Buddy 1
Tera Contributor

Hi,
How to validate a field which should accept only numbers with separators or decimals.
Eg: it should be like 0,00 or 0.00

Can someone help in the validation regex for this requirement. 

Thanks in advance!

1 ACCEPTED SOLUTION

@Buddy 1 ,

 

Try this and let me know:

/^[0-9]{1}[,.][0-9]{2}$/

 

Tried and tested for many use cases and seems it worked for me.

 

PRINCE_ARORA_0-1678951597498.png

 If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

View solution in original post

7 REPLIES 7

Sai Shravan
Mega Sage

Hi @Buddy 1 ,

 

The following regular expression to validate a field that should accept only numbers with separators or decimals in the format of 0,00 or 0.00:

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

^ matches the start of the string
[0-9]+ matches one or more digits
([,.][0-9]{2})? matches an optional group consisting of either a comma or a dot followed by exactly two digits
$ matches the end of the string

 

Regards,
Shravan.
Please mark this as helpful and correct answer, if this helps you

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Hi @Sai Shravan ,

Thanks for the reply. Currently the validation is working, but it is also accepting numbers without separators or decimals. 
So it should be either 0,00 or 0.00 format. But if we try to enter only numbers like 1 or 12 , it should not accept. 
Any suggestions ?

Thanks in advance!

Hi @Buddy 1 ,

 

can you try this

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

Tested in the console 

SaiShravan_0-1678950606163.png

 

Regards,
Shravan.
Please mark this as helpful and correct answer, if this helps you

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Hi @Buddy 1 ,

Did you get the chance to look into the solution?

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you