Entry
What is the best way to verify that an email address is valid in php?
Oct 9th, 2001 11:52
mike gifford, http://www.phpsquare.com/tips/003.html
There are lots of options & different flavours of this.
I've tried the following:
<?
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$",
$Email)) {
$error = 1;
$error_html .= "This email address is invalid: " . $Email;
echo $error_html;
}
?>
But this one looks quite impressive too:
<?
function checkaddress($mail) {
if ( !ereg( "^([0-9,a-z,A-Z]+) ([.,_]
([0-9,a-z,A-Z]+))*[@] ([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]
+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$", $mail ) ) {
return false;
}
else
{
return true;
}
}
?>
More recently I discovered the following :
http://phpclasses.upperdesign.com/browse.html/package/13
which features:
- Simple validation just by looking at the e-mail address string.
- Validation of a e-mail address host as a valid mail exchange domain.
- Validation of a e-mail address by connecting to the mail host server
to determine if there is really a deliverable mail box.
Mike