PHP and Javascript Email Validation of '@' Symbol

后端 未结 4 876
暗喜
暗喜 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-25 01:35

    try this :-

    function isValidEmailAddr ($email) {
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
          return true;
        } else {
          return false;
        }
    }
    

    usage :-

    include('path/to/lib.php');
    $test = 'email@foo.bar';
    if(isValidEmailAddr($test) == true){
     echo "good to go";
    } else { echo "try again babe!" }
    

提交回复
热议问题