Validate email in PHP

SERVER SIDE EMAIL VALIDATION IN PHP

In this tutorial, we will be learning how we can validate email in PHP easily.

<?php 
// Techyadda.in PHP program to validate email 
  
// Function to validate email in PHP 
function email_validator($email) { 
    return (!preg_match( 
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $str)) 
        ? FALSE : TRUE; 
} 
  
// Here we are calling function
if(!email_validator("techyadda19@gmail.com")) { 
    echo "Email address not valid."; 
} 
else { 
    echo "Valid email address."; 
} 
  
?> 

So using the above function you can easily validate email in PHP. People must validate email on the server side (PHP) as one can bypass javascript validation easily.

Please share your suggestion and feedback in the comments. And please also suggest more articles related to Website Development. Thanks for visiting!!!

Leave a Comment

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

PHP Code Snippets Powered By : XYZScripts.com
Contact Techyadda