IT & Programming

Validate an email address with PHP

  • Validate an email address with php.
  • How to validate an email address with php.
  • Validate an email value with php.

Function accepts a parameter and returns false if value is not a valid email address.

Function

function isValidEmail($string){
     
    if(!preg_match("/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}$/i",$string)){
         return false;
     }
}

Calling The Function

$string='example@example.com';

if(isValidEmail($string)!==false){

   echo 'Value is a valid email address';

}else{

   echo 'Value is not a valid email address';
}

Output

Value is a valid email address

Leave A comment

Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *