PHP and Javascript Email Validation of '@' Symbol

后端 未结 4 871
暗喜
暗喜 2021-01-25 01:21

Trying to get code to search if \'@\' symbol is present in typed-in email address and echo if symbol is not. Everything works fine without the searching for @ code.

chec

4条回答
  •  隐瞒了意图╮
    2021-01-25 01:38

    It will not only validate email address, but also sanitize it for unexpected characters:

    $email = $_POST['email'];
    $emailB = filter_var($email,   
     FILTER_SANITIZE_EMAIL); 
     if(filter_var($emailB,   
     FILTER_VALIDATE_EMAIL) === false ||  
     $emailB != $email ) { echo "This email adress 
      isn't valid!"; exit(0);
    }
    

提交回复
热议问题