This function just checks to see if an email address is syntactically correct. It doesn't verify that the address actually exists.
I didn't create this myself, but found it on the net ages ago.
Usage:
<?
if( validate_email($email) == true ){
echo "Yay! $email is valid!";
}else{
echo "Sorry, $email is not a valid email address.";
}
?>
<?php
function validate_email($email){
if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) ||
!eregi ("^.+\@(\[?)[-_a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$", $email)) {
return(false);
} else {
list($user, $domain) = explode("@", $email);
if ((!eregi("^[_a-zA-Z0-9\.\-]+$", $user)) ||
(!eregi("^[_a-zA-Z0-9\.\-]+$", $domain))) {
return false;
} else {
return(true);
}
}
}
?>
|