email address not validating
Posted: Wed Sep 30, 2009 3:35 pm
I have these two methods to assist in validating email addresses.
When I type in trooper@gmail.com as the email address, it tells me that the address is "invalid". I think it's safe to assume the regex is not the issue.
Code: Select all
public static function validateEmail($email) {
$errors = array();
if(!empty($email)) {
if(!System_Validator::isValidEmailAddress($email)) {
$errors[] = 'Invalid email address';
}
} else {
$errors[] = 'You must provide an email address';
}
return $errors;
}
public static function isValidEmailAddress($email) {
// Regex from regular-expressions.info
$regex = '/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/';
if(preg_match($regex, $email)) {
return true;
}
return false;
}