check valid rfc822 email


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function is_valid_email_address($email){
  2.  
  3. $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  4.  
  5. $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  6.  
  7. $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
  8. '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  9.  
  10. $quoted_pair = '\\x5c[\\x00-\\x7f]';
  11.  
  12. $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
  13.  
  14. $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
  15.  
  16. $domain_ref = $atom;
  17.  
  18. $sub_domain = "($domain_ref|$domain_literal)";
  19.  
  20. $word = "($atom|$quoted_string)";
  21.  
  22. $domain = "$sub_domain(\\x2e$sub_domain)*";
  23.  
  24. $local_part = "$word(\\x2e$word)*";
  25.  
  26. $addr_spec = "$local_part\\x40$domain";
  27.  
  28. return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
  29. }

URL: http://www.iamcal.com/publish/articles/php/parsing_email/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.