I need to do a regex on a name field using PHP. The name could be any combination of names
- John Doe
- John O'Doe
- John O' Doe
- John & Mary Doe
- John & Mary O' Doe
- John Doe-Schmoe
etc...
or of course, any combination of the above.
Here is what I tried so far:
Code: Select all
// doesn't work
if (!preg_match("/[^\w\s]/i",$name)) {
$this->setError('NoName');
}
// doesn't work
if (!preg_match("/[a-zA-Z -\'&]*[\s]+[a-zA-Z -\'&]*/i",$name)) {
$this->setError('NoName');
}
// doesn't work
if (preg_match("/([[:digit:]]|[~`!@#$%^*()_=+{}|\:;"/?,]|[|]|-)+//i",$name)) {
$this->setError('NoName');
}