Created
May 7, 2011 00:48
-
-
Save kostasdizas/960089 to your computer and use it in GitHub Desktop.
advanced e-mail validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Checks if the given e-mail is valid | |
* Checks Done: | |
* - Email has correct number of '@' and lengths | |
* - Domain is valid | |
* - Domain has too little parts | |
* - Domain has valid parts | |
* - Domain is IP | |
* - Domain has a DNS MX record | |
* | |
* @return boolean | |
*/ | |
private function checkEmailValidity($email) | |
{ | |
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) return false; | |
list($username, $domain) = explode("@", $email); | |
if (ereg("^\[?[0-9\.]+\]?$", $domain)) return false; | |
$domain_parts = explode(".", $domain); | |
if (sizeof($domain_parts) < 2) return false; | |
foreach ($domain_parts as $d) { | |
$reg1 = "^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$"; | |
if (!ereg($reg1, $d)) return false; | |
$reg2 = "^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$"; | |
if (!ereg($reg2, $d)) return false; | |
} | |
if (!checkdnsrr($domain, 'MX')) return false; | |
return true; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment