How to specify a single quote in a regular expression

Here is my regex. I want to include single quotes (') in characters like (O'Neal Nickel). Here is my regex that allows letters and spaces and complete stops (.) And (-) hyphens

/^[A-Za-z\/\s\.-]+$/; 
+7
source share
3 answers

/^[A-Za-z\/\s\.'-]+$/; Or did I misunderstand your question?

+8
source

Try the following:

 /^[A-Za-z\/\s\.'\-]+$/; 

You do not need backslash / escape single quote. This will cause Safari to forbid single quotes instead of resolving them.

+5
source
 var testName=/^[A-Za-z\/\s\.'-]+$/; var name= $("#name").val(); if(testName.test(name) == false || name == "") {} 

This is the code I used to check the name

0
source

All Articles