I am using regex_match for validation for last names
I have this so far regex_match[/^[a-zA-Z -]{0,25}+$/] but I also want to allow ' for names like O’Neal. I tried this regex_match[/^[a-zA-Z -\']{0,25}+$/] but it didnt work
any suggestions?
Thanks,
J
-\'is an invalid range. You need to put the dash at the end of the character class:The
+is superfluous here (in some regex flavors, it activates “possessive matching”, but it’s definitely not needed here), as is the backslash.Also, I suspect that the square brackets around the regex are not syntactically correct in whatever language you’re using. (Which one is that, by the way?)
But the real problem is your trying to validate a name (with a regex, no less).