validating username
Posted: Thu Mar 15, 2007 6:59 am
Hi All,
I'm trying to validate a name containing only a-z, A-Z and hyphen, I found the following function works but looks illogical to me. Could you help me out?
Thanks.
I'm trying to validate a name containing only a-z, A-Z and hyphen, I found the following function works but looks illogical to me. Could you help me out?
Thanks.
Code: Select all
function nameValid($name){
$name = trim($name);
if(strlen($name)>0){
if(!ereg('[^a-zA-Z-]{1,}', $name)){ // I am surprised at this line but looks like it works! Please help me out!
return true;
}
else{
return false;
}
}
else{
return false;
}
}