Here is my regular expression . I want to include single quotes (') within the characters such as (O'Neal Nickel). Here is my regular expression allowing letters and spaces and full stops(.) and (-) hyphens
/^[A-Za-z\/\s\.-]+$/; 34 Answers
/^[A-Za-z\/\s\.'-]+$/; Or did I get your question wrong?
Try this:
/^[A-Za-z\/\s\.'\-]+$/; You do not need to backslash/escape the single quote. Doing so will cause Safari to disallow single quote marks instead of allowing them.
2var testName=/^[A-Za-z\/\s\.'-]+$/; var name= $("#name").val(); if(testName.test(name) == false || name == "") {} This is a code I used to check name
0/^[A-Za-z\/\s\.'-]+$/
@Urasquirrel - you asked for detailed explanation and I know that whenever I see questions like this, I want the same thing!!
^ - beginning of the string [ - allowed characters are contained in the square brackets A-Z - uppercase A to Z a-z - lowercase a to z \/ - escaped forward slash \s - whitespace \. - escaped period ' - single quote - - a dash ] - end of square brackets + - ONE of more of the allowed characters contained in the square brackets $ - end of string is a great place to test different RE patterns with different strings and different languages. there are other sites that do similar