Validations on variable text field - Allow only Numbers and Special Characters

KARAN24
Tera Contributor

Hi All,

I want a validation  in my variable - only numbers and special characters should be allowed

Below code did not work. Can someone please help with the code for all the validations.

var pattern = /^[_A-z]*((-|\s)*[_A-z])*$/;

var name = g_form.getValue('number');

if (!pattern.test(number)){

g_form.addErrorMessage("Only Numbers and Characters are allowed");

}

}

 Thanks,

Karan

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can easily do this using Variable Validation RegEx

Then attach this to the variable you wish to

No need of client script

1) Regex -> ^(?=.*?[1-9])[0-9()-]+$

find_real_file.png

2) Link this with the variable

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@KARAN 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@KARAN 

Hope you are doing good.

Did my reply answer your question?

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Thanks!
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar,

Greetings !!!

The requirement that I have is to allow space as well as plus(+) character in addition to numbers and other special characters. Could you please guide me how can I modify following Regex to fulfil my requirement ?

Regex: ^(?=.*?[1-9])[0-9()-]+$

Would appreciate your help in this matter.

Thanks & Regards,

Gulzar Manuja