note 46033 deleted from function.preg-match by tomsommer
| From: | tomsommer@php.net | Date: | Mon, 27 Sep 2004 21:05:28 +0000 |
| Subject: | note 46033 deleted from function.preg-match by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77450@lists.php.net to get a copy of this message | ||
Note Submitter: retry at whatnet dot org
----
Here's something to help out all the nubs -- a nice email validation regex. It doesn't
handle IP addressed domains, but who cares.
It allows . and - characters but not as leading or trailing chars. It also won't allow repeats
of said chars.
will match: u.r.teh.sux0r@hotmail.com
won't match -blah-@blah.u.go.girl.com
or bla--h@red.herrning.net
peace out
-- retry
NOTE: remove the spaces in the regex
function checkEmail($email) {
if ( !preg_match(
"#^[\w|\d] +(([\-|\.][\w|\d]+)+) ?@([\w|\d|\-]+\.)+[\w]{2,3}$#"
, $email) ) return 1;
return 0;
}
then use it like this in your scripts:
if ( checkEmail($instanceEmail) ) $errormsg = "Your email address blows.";