uhm since you're checking an e-mail, you should probably be using filters instead of regex.
PHP: filter_var - Manual
Which will return false if it doesn't pass the character test. Over on another forums a group of us came up with this function for testing an e-mail address -- it's about as robust and bulletproof as you're gonna get:
Code:
function common_isValidEmail($address) {
/* check namespace */
if (filter_var($address,FILTER_VALIDATE_EMAIL)==FALSE) {
return false;
}
/* explode out local and domain */
list($local,$domain)=explode('@',$address);
$localLength=strlen($local);
$domainLength=strlen($domain);
return (
/* check for proper lengths */
($localLength>0 && $localLength<65) &&
($domainLength>3 && $domainLength<256) &&
(
/* is valid/registered domain name? */
checkdnsrr($domain,'MX') ||
checkdnsrr($domain,'A')
)
);
}
Since it uses filter_var to check the character space, explodes to test the length of the local and domain against the specification limits, AND checks that the domain name is in fact a valid/registered one with a DNS lookup.
Hope this helps.
Bookmarks