My aim is to validate a last name by allowing it to only contain letters or a single quote. I do not know what the fastest way is..maybe regex I suppose.. Anyway, so far I have this:
function check_surname($surname)
{
$c = str_split($surname,1);
$i = 0;
$test = 1; // Wrong surname
while($i < strlen($surname))
{
if(ctype_alpha($c[$i]) or $c[$i] == '\'')
{
$test = 0;
$i++;
}
else
{
return false;
}
}
}
I can feel that something is wrong here but I can't see where it is. Could anyone help me out?