How to validate email in php

php

Posted on 13 Feb 15 by Vickey
  369



We can validate email by using eregi function by giving our email pattern

function isValidEmail($email)
{
        $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
        if (eregi($pattern, $email))
         return true;
        else 
         return false;
 }

and you can call it

$email='example@gmail.com';
if(isValidEmail($email)){

 // do something..................

}

 


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com