Validate email address using PHP

Sharing is caring!

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 = "mahmud@thinkdiff.net";
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  = "mahmud@thinkdiff.net";
 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
"; }

People found this article was interesting about:


Sameera Mallawaarachchi A Photographer • Tech Enthusiastic • Android Lover • True believer in Google • Founder of KathaBuzz.com and SamSeen.com

Leave a Reply

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