320) { return false; } if (! preg_match('/^' . EMAIL_PATTERN_LOCALPART . '@/', $email, $matches)) { return false; } if (strlen($matches[0]) > 65) { // 64 character max for the local part + 1 character for @ return false; } $domain = substr($email, strlen($matches[0])); if (! preg_match('/^' . EMAIL_PATTERN_DOMAIN_NORMAL . '$/', $domain)) { if (preg_match('/^' . EMAIL_PATTERN_DOMAIN_IP . '$/', $domain)) { return true; } if (preg_match('/^' . EMAIL_PATTERN_DOMAIN_BRACKET . '$/', $domain)) { $domain = trim(substr($domain, 1, strlen($domain) - 2)); } else { return false; } } if (strlen($domain) > 253) { return false; } $labels = array(); $thisLabel = ''; $domainSplit = str_split($domain); while (count($domainSplit)) { if ($domainSplit[0] == '.') { array_shift($domainSplit); if ($thisLabel == '') { return false; } $labels[] = $thisLabel; $thisLabel = ''; } else { if ($domainSplit[0] == '\\') { $thisLabel .= array_shift($domainSplit); } $thisLabel .= array_shift($domainSplit); } } if ($thisLabel == '') { return false; } if (! preg_match('/^[a-zA-Z]{1,63}$/', $thisLabel)) { return false; } foreach ($labels as $label) { if (strlen($label) > 63) { return false; } if (substr($label, 1) == '-' || substr($label, - 1) == '-' || strpos($label, '--') !== false) { return false; } } return true; }