Your Ad Here

Posted By

misteroneill on 08/23/09


Tagged

email validation


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

vali29
abhinavsood
umang_nine


Check for Valid Email Address


 / Published in: PHP
 

URL: http://www.misteroneill.com

This is a pretty robust email address validation function I came across that hasn't failed me yet.

  1. function is_valid_email_address($email) {
  2. $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  3. $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  4. $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  5. $quoted_pair = '\\x5c[\\x00-\\x7f]';
  6. $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
  7. $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
  8. $domain_ref = $atom;
  9. $sub_domain = "($domain_ref|$domain_literal)";
  10. $word = "($atom|$quoted_string)";
  11. $domain = "$sub_domain(\\x2e$sub_domain)*";
  12. $local_part = "$word(\\x2e$word)*";
  13. $addr_spec = "$local_part\\x40$domain";
  14. return preg_match("!^$addr_spec$!", $email) ? true : false;
  15. }

Report this snippet  

You need to login to post a comment.