function isValidEmail($email) {
$email = strtolower($email);
if (!preg_match(“/[^@]{1,64}@[^@]{1,255}/”, $email)) {
return false;
}
$email_array = explode(“@”, $email);
$local_array = explode(“.”, $email_array[0]);
$length = sizeof($local_array);
for ($i = 0; $i < $length; $i++) {
if (!preg_match(“@^[a-z0-9_~-][a-z0-9_~.-]{0,63}$@”, $local_array[$i])) {
return false;
}
}
unset($length);
if (!preg_match(“@^[?[0-9.]+]?$@”, $email_array[1])) {
$domain_array = explode(“.”, $email_array[1]);
$length = sizeof($domain_array);
if ($length < 2) {
return false;
}
for ($i = 0; $i < $length; $i++) {
if (!preg_match(“/^(([a-z0-9][a-z0-9-]{0,61}[a-z0-9])|([a-z0-9]+))$/”, $domain_array[$i])) {
return false;
}
}
unset($length);
}
return true;
}