How to validate an Email in PHP?

后端 未结 7 851
梦毁少年i
梦毁少年i 2020-11-22 05:20

How can I validate the input value is a valid email address using php5. Now I am using this code

function isValidEmail($email){ 
     $pattern = \"^[_a-z0-9         


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 06:11

    User data is very important for a good developer, so don't ask again and again for same data, use some logic to correct some basic error in data.

    Before validation of Email: First you have to remove all illegal characters from email.

    //This will Remove all illegal characters from email
    $email = filter_var($email, FILTER_SANITIZE_EMAIL);
    

    after that validate your email address using this filter_var() function.

    filter_var($email, FILTER_VALIDATE_EMAIL)) // To Validate the email
    

    For e.g.

    
    

提交回复
热议问题