我有这个使用jquery验证的应用程序。 (已停止使用数据注释:()
在提交和模糊时,我想检查重复值。由于这是我第一次遇到jquery验证(除了数据注释),我不确定这里最好的方法是什么。这里还有一个远程呼叫。我正在考虑一些像下面这样的事情。这是正确的方法吗?
$("#" + enums.RegisterUsername).rules("add", {
onkeyup: false,
**onfocusout/onblur: true, ?????????**
required: true,
minlength: 6,
alphanumericwithbasicpunc: true,
remote: SignUp.DuplicateUserIdCheckUrl,
messages: {
required: "<span style='color:red'> Required</span>",
minlength: "<span style='color:red'>User name must be at least 6 characters in length.</span>",
alphanumericwithbasicpunc: "<span style='color:red'>User name cannot contain the following characters: &,\, /, #, <, or >.</span>",
remote: "<span style='color:red'>User name already taken by another user.</span>"
}
});
由于
答案 0 :(得分:1)
你绝对不能在.validate()
方法中放置任何.rules()
方法选项。只有规则(和messages
)才能进入。
$("#" + enums.RegisterUsername).rules("add", {
required: true,
minlength: 6,
alphanumericwithbasicpunc: true,
remote: SignUp.DuplicateUserIdCheckUrl,
messages: {
required: "<span style='color:red'> Required</span>",
minlength: "<span style='color:red'>User name must be at least 6 characters in length.</span>",
alphanumericwithbasicpunc: "<span style='color:red'>User name cannot contain the following characters: &,\, /, #, <, or >.</span>",
remote: "<span style='color:red'>User name already taken by another user.</span>"
}
});
此外,在每种情况下,onfocusout
永远不能设置为true
。验证模糊已经是默认行为,因此将此选项设置为true
可能会破坏插件。如果要禁用它,或者设置为覆盖它的功能,它只能设置为false
。如果您希望在模糊时进行验证,则需要将onfocusout
选项排除在.validate()
之外。
答案 1 :(得分:0)
我评论并测试了以下内容。它正在努力模糊。
$("#" + enums.RegisterUsername).rules("add", {
//onkeyup: false,
//onfocusout: true,
required: true,
minlength: 6,
alphanumericwithbasicpunc: true,
remote: enums.DuplicateUserIdCheckUrl,
messages: {
required: "<span style='color:red'> Required</span>",
minlength: "<span style='color:red'> User name must be at least 6 characters in length.</span>",
alphanumericwithbasicpunc: "<span style='color:red'> User name cannot contain the following characters: &,\, /, #, <, or >.</span>",
remote: "<span style='color:red'> User name already taken by another user.</span>"
}
});