PHP Email Validation


/ Published in: PHP



Copy this code and paste it in your HTML
  1. <?php
  2. /**
  3.  * This function validates an email address, returning an integer
  4.  * depending on whether or not the email address provided is valid.
  5.  * A positive match will yield a result of 1, while a negative match
  6.  * will yield a result of 0. FALSE will be returned if an error occurred.
  7.  *
  8.  * @param string $email The email address to validate.
  9.  * @return integer The result of the validation.
  10.  */
  11. function isValidEmail( $email = null )
  12. {
  13. return preg_match( "/^
  14. [\d\w\/+!=#|$?%{^&}*`'~-]
  15. [\d\w\/\.+!=#|$?%{^&}*`'~-]*@
  16. [A-Z0-9]
  17. [A-Z0-9.-]{1,61}
  18. [A-Z0-9]\.
  19. [A-Z]{2,6}$/ix", $email );
  20. }
  21. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.