Here is my regular expression . I want to include single quotes (') within the 开发者_JS百科characters such as (O'Neal Nickel). Here is my regular expression allowing letters and spaces and full stops(.) and (-) hyphens
/^[A-Za-z\/\s\.-]+$/;
/^[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.
/^[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
https://regex101.com/ is a great place to test different RE patterns with different strings and different languages. there are other sites that do similar
var testName=/^[A-Za-z\/\s\.'-]+$/;
var name= $("#name").val();
if(testName.test(name) == false || name == "")
{}
This is a code I used to check name
精彩评论