I have a this regular expression below for some input name fields. How do I include an apostrophe and a hyphen in this?
JavaScript
x
2
1
InputField("tFName", /^[a-zA-Z-- ]+$/);
2
Advertisement
Answer
Hyphen is already included (twice), you can add the apostrophe by just editing it into the character class:
JavaScript
1
2
1
/^[a-zA-Z-- ']+$/
2
You can rewrite it to look like this, so that there’s no need to escape the hyphen and it’s only included once:
JavaScript
1
2
1
/^[a-zA-Z '-]+$/
2
Example: http://jsfiddle.net/a4vGA/