JQuery用户名验证 [英] JQuery Username Validation
问题描述
有没有人使用jquery验证和jquery addmethod有一个用户名检查器的工作示例?
Does anyone have a working example of a username checker using jquery validation and jquery addmethod?
这样的事情:
$("#register_form").validate({
onkeyup:false,
rules: {
username: {
required: true,
minlength: 3,
usernameCheck: true // remote check for duplicate username
},
});
jQuery.validator.addMethod("usernameCheck", function(username) {
var isSuccess = false;
$.ajax({
url: "username_availability.php",
data: "username=" + username,
async: false,
type: "POST",
success:
function(msg) {
isSuccess = parseInt(msg);
}
});
return isSuccess;
},"");
我已经在谷歌看了好几天了,我注意到了很多线程这个没有答案或没有解决的高视图数。因此,如果有人可以提供链接或解决方案,我相信很多JQuery新手会受益并且很高兴。 :)
I've been looking all over Google for days, and I've noticed a number of threads like this that go unanswered or unsolved with a high view count. So if someone could provide a link or a solution, I'm sure a lot of JQuery noobs would benefit and be glad. :)
嘿,伙计们,非常感谢你们所有的
帮助。我设法找到了我的
寻找的东西。
Hey guys, thanks a lot for all your help. I managed to find what I was looking for though.
牛奶的例子?真?它存在吗?
The "milk example"? Really? It exists?
- 是的,我的儿子,它存在并且很棒:
http://jquery.bassistance.de/validate/demo/milk/
--Yes my son, it exists and it's awesome: http://jquery.bassistance.de/validate/demo/milk/
推荐答案
我认为你的问题是你返回时没有调用成功方法。您可以将代码更改为:
I think your problem is that the the success method isn't being called by the time you return. You can change your code to be:
jQuery.validator.addMethod("usernameCheck", function(username) {
var result = $.ajax({
url: "username_availability.php",
data: {username: username},
async: false,
type: "POST"
}).responseText;
return result === '1';
},"");
这篇关于JQuery用户名验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!