How do I include – and ‘ in this regular expressions?

Tags: ,

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 there’s no need to escape the hyphen and it’s only included once:

/^[a-zA-Z '-]+$/


Source: stackoverflow