How to validate an Email in PHP?

后端 未结 7 737
梦毁少年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:16

    Use:

    • or "filter_var" from http://php.net/manual/en/function.filter-var.php
    var_dump(filter_var('bob@example.com', FILTER_VALIDATE_EMAIL));
    
    • or "EmailValidator" from https://github.com/egulias/EmailValidator
    $validator = new EmailValidator();
    $multipleValidations = new MultipleValidationWithAnd([
        new RFCValidation(),
        new DNSCheckValidation()
    ]);
    $validator->isValid("example@example.com", $multipleValidations); //true
    

提交回复
热议问题