PHP判断邮件地址方法
function check_email_address($email) {
// first, we check that there"s one @ symbol, and that the lengths are right
if (!ereg("{1,64}@{1,255}", $email)) {
// email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(({0,63})|(\"{0,62}\"))$", $local_array)) {
return false;
}
}
if (!ereg("^\+\]?$", $email_array)) { // check if domain is ip. if not, it should be valid domain name
$domain_array = explode(".", $email_array);
if (sizeof($domain_array) < 2) {
return false; // not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(({0,61})|(+))$", $domain_array)) {
return false;
}
}
}
return true;
}