php email regex - validating email address using regular expression


SUBMITTED BY: phpsnippets

DATE: Oct. 21, 2015, 2:06 p.m.

FORMAT: Text only

SIZE: 243 Bytes

HITS: 1552

  1. <?php
  2. $regex = "/([a-z0-9_]+|[a-z0-9_]+\.[a-z0-9_]+)@(([a-z0-9]|[a-z0-9]+\.[a-z0-9]+)+\.([a-z]{2,4}))/i";
  3. // usage
  4. if(!preg_match($regex, $email)) {
  5. echo "Invalid email address";
  6. }
  7. else {
  8. echo "email is valid";
  9. }
  10. ?>

comments powered by Disqus