webref.eu Posted July 29, 2008 Share Posted July 29, 2008 Hi All Could anyone give me or point me in the direction of a good current e-mail validation function? Thanks all. Link to comment https://forums.phpfreaks.com/topic/117173-looking-for-good-e-mail-validation-function/ Share on other sites More sharing options...
revraz Posted July 29, 2008 Share Posted July 29, 2008 Check the Resources Sticky here http://www.phpfreaks.com/forums/index.php/board,43.0.html You'll find several expressions to use. Link to comment https://forums.phpfreaks.com/topic/117173-looking-for-good-e-mail-validation-function/#findComment-602696 Share on other sites More sharing options...
TempleDMDKrazd Posted July 29, 2008 Share Posted July 29, 2008 as in the email is the right format? Check out the "Regular Expression" forum.... Link to comment https://forums.phpfreaks.com/topic/117173-looking-for-good-e-mail-validation-function/#findComment-602698 Share on other sites More sharing options...
vbnullchar Posted July 29, 2008 Share Posted July 29, 2008 From Kohana Framework... <?php /** * Validate email, commonly used characters only * * @param string email address * @return boolean */ public static function email($email) { return (bool) preg_match('/^(?!\.)[-+_a-z0-9.]++(?<!\.)@(?![-.])[-a-z0-9.]+(?<!\.)\.[a-z]{2,6}$/iD', $email); } /** * Validate email, RFC compliant version * Note: This function is LESS strict than valid_email. Choose carefully. * * @see Originally by Cal Henderson, modified to fit Kohana syntax standards: * @see http://www.iamcal.com/publish/articles/php/parsing_email/ * @see http://www.w3.org/Protocols/rfc822/ * * @param string email address * @return boolean */ public static function email_rfc($email) { $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; $pair = '\\x5c[\\x00-\\x7f]'; $domain_literal = "\\x5b($dtext|$pair)*\\x5d"; $quoted_string = "\\x22($qtext|$pair)*\\x22"; $sub_domain = "($atom|$domain_literal)"; $word = "($atom|$quoted_string)"; $domain = "$sub_domain(\\x2e$sub_domain)*"; $local_part = "$word(\\x2e$word)*"; $addr_spec = "$local_part\\x40$domain"; return (bool) preg_match('/^'.$addr_spec.'$/D', $email); } ?> Link to comment https://forums.phpfreaks.com/topic/117173-looking-for-good-e-mail-validation-function/#findComment-602699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.