Regular expression - allow special characters and letters in single text box

prabhmeet
Giga Expert

Hi,

I have to write  a regular expression to allow only characters (no numbers), No spaces before and after string, and allow special characters ' " -  these 3 characters anywhere in the text field.

Please help me modify the below code - 

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

var name = g_form.getValue('updated_first_name');
if (!pattern.test(name)){


g_form.addErrorMessage("Only Characters are allowed");
g_form.setValue('updated_first_name','');

}

1 ACCEPTED SOLUTION

Matthew Glenn
Kilo Sage

Try this for your pattern:

/^[a-zA-Z'"-](\S)*$/

 

View solution in original post

6 REPLIES 6

Sure I did.. Can you explain me the difference between /^[A-Za-z'"-]*$/ and /^[A-Za-z'"-](\S)*$/ if you know?

Matthew Glenn
Kilo Sage

Try this for your pattern:

/^[a-zA-Z'"-](\S)*$/