function emailtest($email) { if(filter_has_var(INPUT_GET, "email")) {
echo("Input type does not exist"); } else { if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL)) { echo "E-Mail is not valid"; } else { echo "E-Mail is valid"; } } } ?>
</body> </html>
------解决方案-------------------- 。。。我的话很有深意? filter_input()如果验证没通过,才会返回false if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL)) { echo "E-Mail is not valid"; } 这句如果变量合法,返回的却是not valid
------解决方案-------------------- function validateEmail($email){ return preg_replace("/^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/", $email); }
if(!validateEmail($_POST['email'])){ echo "<strong>Invalid E-mail:</strong> Type a valid e-mail please ."; } 希望可以帮到你