I am trying to use preg_match and filter_var to check form entries. I created two functions that should return false when the fields contain invalid characters. For the Username, the invalid characters would be numbers and symbols. Whats wrong with my functions?
username function:
function verifyUsername($x){
if (!preg_match('/[^a-z\s-]/i',$x)) {
return 0;
}
else {
return 1;
}
}
email address function:
function verifyEmailAdd($x){
if (!filter_var($emailadd, FILTER_VALIDATE_EMAIL)) {
return 0;
}
else {
return 1;
}
}
I am calling them like:
goodemail = verifyEmailAdd($emailAdd);
gooduser = verifyUsername($userName);
They always return 1.