gpt4 book ai didi

javascript - 远程验证

转载 作者:行者123 更新时间:2023-11-30 06:08:42 24 4
gpt4 key购买 nike

下面是我的代码,验证只在没有远程验证的情况下有效。一旦我包含远程验证,它就提交表单而不完成所有其他表单验证?

    $(document).ready(function() {


$("#form1").validate({
rules: {
firstName: "required",// simple rule, converted to {required:true}
lastName: "required",
email: {// compound rule
required: true,
email: true,
success: "valid",
remote: "checkAddress.php"
},
password: {
required: true,
success: "valid",
minlength: 5
},

verify: {
required: true,
success: "valid",
minlength: 5,
equalTo: "#password"
},
address1: "required",
city: "required",
province: "required",

dob: {
required: true,
date: true,
success: "valid"
},


captcha_code: {
required: true,
captcha_code: true,
remote: "checkCaptcha.php"
}

},
messages: {
email:{
remote: "This email is already registered! One registration per email address."
},
captcha_code:{
remote: "Enter the right captcha value!."
}
},
onsubmit: true
});
});

最佳答案

我想问的是,您是否已将验证码作为一种方法来实现?在 captcha_code: true, 中。

 captcha_code: {
required: true,
captcha_code: true,
remote: "checkCaptcha.php"
}

像这样

jQuery.validator.addMethod("captcha_code", function(value, element) {
return (this.optional(element) || /* do something */ );
}, "");

我找到了这个验证码演示,它没有验证码作为方法,只有必需的和远程的。所以我在想你是否实现了它。

这是演示中的脚本。 http://jquery.bassistance.de/validate/demo/captcha/

$(function(){
$("#refreshimg").click(function(){
$.post('newsession.php');
$("#captchaimage").load('image_req.php');
return false;
});

$("#captchaform").validate({
rules: {
captcha: {
required: true,
remote: "process.php"
}
},
messages: {
captcha: "Correct captcha is required. Click the captcha to generate a new one"
},
submitHandler: function() {
alert("Correct captcha!");
},
success: function(label) {
label.addClass("valid").text("Valid captcha!")
},
onkeyup: false
});

});

关于javascript - 远程验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2106167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com