- b2evolution CMS Support Forums
- b2evolution Support
- Plugins & Extensions
- Improved E-mail Format Regex Checker
1 kwa Sep 15, 2005 06:48
I've found an interesting e-mail checking regular expression found on [url=http://www.regexlib.com/REDetails.aspx?regexp_id=284]RegExLib.com[/url]:
/^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/i
I've tested it on all the 215 unique e-mail addresses found on my blog and it appeared it found 10 wrong addresses (all 10 are really wrong) where the original (v0.9.0.11) regex:
/^.+@[^\.].*\.[a-z]{2,}$/i
identifies "only" 8 wrong e-mail addresses.
If you want to improve your e-mail addresses verification process, update the is_email() function found in b2evocore/_functions.php about lines 478-492:
/*
* is_email(-)
*
* Check that email address looks valid
*/
function is_email($user_email) {
#$chars = "/^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$/i";
//$chars = '/^.+@[^\.].*\.[a-z]{2,}$/i';
$chars = '/^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/i';
if(strstr($user_email, '@') && strstr($user_email, '.')) {
return (bool)(preg_match($chars, $user_email));
} else {
return false;
}
}
Other interesting patterns can be found on [url=http://www.regexlib.com/DisplayPatterns.aspx]Regular Expression Library (Patterns)[/url].
You can use the [url=http://www.koralsoft.com/regextester/]REGex TESTER[/url] to check those regular expressions with your e-mail database (remove the starting '/^' and the ending '$/i' before testing).