Posted By

gdonald on 01/12/07


Tagged

regex email php


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

basicmagic
vali29
hudge


PHP Valid Email


 / Published in: PHP
 

  1. error_reporting( E_ALL );
  2.  
  3. function is_valid_email( $email )
  4. {
  5. return preg_match( '/[.+a-zA-Z0-9_-]+@[a-zA-Z0-9-]+.[a-zA-Z]+/', $email );
  6. }
  7.  
  8. $emails = array( 'br0k3n',
  9. '[email protected]',
  10. '[email protected]',
  11. '[email protected]',
  12. '[email protected]' );
  13.  
  14. foreach( $emails as $email )
  15. {
  16. echo $email . ' is' . ( is_valid_email( $email ) ? '' : ' not' ) . " valid\n";
  17. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: tylerhall on January 12, 2007

The above code doesn't work. It lets through the following invalid email addresses:

  • .[email protected] (email cannot start with a period)
  • tyler@foocom (no period between domain and tld)
  • [email protected] (invalid tld)

Also, your regex is limiting the use of many other ASCII characters that RFC-2822 allows in an email address.

Posted By: collin on January 12, 2007

See http://www.ilovejackdaniels.com/php/email-address-validation/ for the proper way to do RFC 2822 validation.

Posted By: onetimeuser on August 1, 2009

http://www.ilovejackdaniels.com/php/email-address-validation/

Has been Relocated by request of the TRADEMARK.

HERE is the new link: http://www.addedbytes.com/php/email-address-validation/

You need to login to post a comment.