Looking for a regex to check a valid English name, i.e.:
- A-Z, a-z,
space
only - First name, (optional) Middle name, Last name
An acceptable example: John von Neumann
Thanks!
EDIT (added checking code):
#!/usr/bin/php
<?php
function check_name($regex, $name)
{
$rc = 'Bad';
if (preg_match($regex, $name)) {
$rc = 'Good';
}
return '|' . $name . '| ' . $rc . "\n";
}
$regex = '/(?:[A-Za-z]+(?:\s+|$)){2,3}/';
echo check_name($regex, 'First');
echo check_name($regex, 'First Last');
echo check_name($regex, 'Two Spaces');
echo check_name($regex, 'First Middle Last');
echo check_name($regex, 'First Middle Last Fourth');
echo check_name($regex, 'First 123');
?>