- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2019 09:06 AM
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','');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2019 09:33 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2019 09:31 AM
Hi,
here is the correct pattern to accept only the mentioned characters.
pattern = /^[A-Za-z'"_]*$/
Mark correct if this solves your problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2019 10:20 AM
Hi Prabhmeet,
just for refernce, did my code did not work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2019 10:42 AM
Hi asifnoor,
Your code also worked, only it had an underscore_ instead of hyphen-, but it was just a typing mistake.
I am not sure what's the difference between /^[A-Za-z'"_]*$/ and /^[A-Za-z'"_](\S)*$/ as both did not allow any space.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2019 01:35 PM
Ah okay, i thought it was underscore only. Anyways, problem got solved, that's important.
Kindly mark my comment as helpful if it worked.