DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

PHP Email Validation Function

02.17.2006
| 95442 views |
  • submit to reddit
        // Simple function to check if an given email adddress is valid

function is_valid_email($email) {
  $result = TRUE;
  if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
    $result = FALSE;
  }
  return $result;
}
    

Comments

Snippets Manager replied on Fri, 2010/04/09 - 1:37pm

A pretty good validation script (a bit more robust than the one given here) is available at the useful php blog email validator

Snippets Manager replied on Tue, 2009/01/27 - 9:46am

Try this against some of the test cases here: http://www.dominicsayers.com/isemail/