我有一个关于 php 验证的问题,我有这个脚本
$(document).ready(function(){
// validate signup form on keyup and submit
var validator = $("#contactform").validate({
rules: {
email: {
email: true,
required: true,
remote: { url: "test.php", type: "post" }
}
},
messages: {
email: {
email: "Enter a valid email adress",
required: "This input is required",
remote: "Email adress is in use"
}
},
// set this class to error-labels to indicate valid fields
success: function(label) {
label.addClass("checked");
}
});
});
并且来自 test.php 的验证脚本是
define('__ROOT__', dirname(dirname(dirname(__FILE__))));
require_once (__ROOT__.'/config.php');
$email = mysql_real_escape_string($_POST['email']);
$SQL = $mysqli->query("SELECT * FROM users WHERE email='$email'");
If($SQL->num_rows == 0) {
echo 'true';
} else {
echo 'false';
}
如何使 php 文件的验证更复杂,例如:我想添加一个规则来检查电子邮件是否有效(以防万一有人没有激活 javascript)但是如果我尝试这样的验证如果电子邮件地址在数据库中,脚本不会返回错误消息
If(filter_var($email, FILTER_VALIDATE_EMAIL) == false) {
$SQL = $mysqli->query("SELECT * FROM users WHERE email='$email'");
If($SQL->num_rows == 0) {
echo 'true';
} else {
echo 'false';
}
}