PHP: Validate an email address.

Posted October 2nd, 2010


The following function does a very simple check on the supplied string to help ensure it is a valid email address.

<?php
function validEmail($email) {
 if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email))
   return TRUE;
 else
   return FALSE;
}
?>