I have a this regular expression below for some input name fields. How do I include an apostrophe and a hyphen in this?
InputField("tFName", /^[a-zA-Z-\-\ ]+$/);
I have a this regular expression below for some input name fields. How do I include an apostrophe and a hyphen in this?
InputField("tFName", /^[a-zA-Z-\-\ ]+$/);
Hyphen is already included (twice), you can add the apostrophe by just editing it into the character class:
/^[a-zA-Z-\-\ ']+$/
You can rewrite it to look like this, so that theres no need for escaping the hyphen and it's only included once:
/^[a-zA-Z '-]+$/
Example: http://jsfiddle.net/a4vGA/
Try this:
"abc'def ghi-jkl mno-pq'rst".match(/^[\w\s-']+$/)
\w
for any letter \s
for space-
for hyphen'
for apostrophe