note 84283 deleted from function.preg-match by danbrown

From: Date: Wed, 03 Aug 2011 13:12:24 +0000
Subject: note 84283 deleted from function.preg-match by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-182154@lists.php.net to get a copy of this message
Note Submitter: Tim ---- For those not so familiar with regex's, I post my algorithmic email validation routine. It can more easily be changed for individual needs than regex's. My function does NOT recognize exotic email addresses as allowed by RFC. (For example, info@exotic%&$#mail.com is a legal email address but not allowed by my function.) -Tim <?php function email_is_valid($email) { if (substr_count($email, '@') != 1) return false; if ($email{0} == '@') return false; if (substr_count($email, '.') < 1) return false; if (strpos($email, '..') !== false) return false; $length = strlen($email); for ($i = 0; $i < $length; $i++) { $c = $email{$i}; if ($c >= 'A' && $c <= 'Z') continue; if ($c >= 'a' && $c <= 'z') continue; if ($c >= '0' && $c <= '9') continue; if ($c == '@' || $c == '.' || $c == '_' || $c == '-') continue; return false; } $TLD = array ( 'COM', 'NET', 'ORG', 'MIL', 'EDU', 'GOV', 'BIZ', 'NAME', 'MOBI', 'INFO', 'AERO', 'JOBS', 'MUSEUM' ); $tld = strtoupper(substr($email, strrpos($email, '.') + 1)); if (strlen($tld) != 2 && !in_array($tld, $TLD)) return false; return true; } ?>

« previous php.notes (#182154) next »