Sorry guys, but your regexp fails on hyphenated first names, like Anne-Marie.
It also allows for an entire sentence to be typed, as long as you continue to use the correct characters. Your regexp will match "The quick brown fox jumped over the lazy dog" and miss "anne-marie smith".
Try:
<?
$name = array(
"Bob O'Malley",
"Bob De Temple",
"Bob DeTemple",
"Bob 0'm8lly",
"Bob De T3mple",
"Bob DeT3mple",
"BobDeTemple",
"Bob De-Temple",
"Bob O Mally",
"bob de temple" ,
"Anne-Marie smith",
"The quick brown fox jumped over the lazy dog",
"John Smith",
"Jonny-boy o'Henry-james III",
);
foreach($name as $aname){
if(preg_match("/^([a-zA-Z'-]+\s*){2,5}$/",$aname))
echo "Matches: $aname\n";
}
?> Note the {2,5} near the end of my regexp. That indicates that there is a minimum of 2 "name parts" and a maximum of 5 "name parts". "Jonny-boy o'Henry-james III" has 3 name parts. something like "William Patrick Henry O Mally III" would fail to match, as that is a 6 part name, despite being a valid Irish Catholic name. Also, names like Madonna will clearly fail to match, as they're only 1 name part.
-Dan