note 84283 added to function.preg-match

From: Date: Mon, 07 Jul 2008 21:51:37 +0000
Subject: note 84283 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-141248@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 91.66.36.143 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/84283 Del: integrated -- https://master.php.net/note/delete/84283/integrated Del: useless -- https://master.php.net/note/delete/84283/useless Del: bad code -- https://master.php.net/note/delete/84283/bad+code Del: spam -- https://master.php.net/note/delete/84283/spam Del: non-english -- https://master.php.net/note/delete/84283/non-english Del: in docs -- https://master.php.net/note/delete/84283/in+docs Del: other reasons-- https://master.php.net/note/delete/84283 Reject -- https://master.php.net/note/reject/84283 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#141248) next »