Validate email address using PHP

You need to validate email addresses when you create contact forms and other kinds of forms when you need get users email address.

Its simple, this is how to validate and email address using PHP code.

Normal way

$email = "";
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
  echo "Valid email address.";
else {
  echo "Invalid email address.";

This is how to do that using PHP filter function.

$email  = "";
 if(filter_var($email, FILTER_VALIDATE_EMAIL)){
      echo " $email is valid email address 
"; }elseif(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE){ echo " $email is not a valid email address
"; }

Add a Comment

Your email address will not be published. Required fields are marked *