时间:2021-08-01 08:56:28 | 栏目:jquery | 点击:次
本文实例为大家分享了jquery验证用户名是否重复的具体代码,供大家参考,具体内容如下
$("#form-admin-add").validate({ rules:{ userName:{ required:true, minlength:2, maxlength:16, remote: { type: "post", url: "/checkUserName.html", data: { userName: function() { return $("#userName").val(); } }, dataType: "html", dataFilter: function(data, type) { var data=JSON.parse(data) if (data.status ==400) return false; else return true; } } }, password:{ required:true, }, password2:{ required:true, equalTo: "#password" }, sex:{ required:true, }, phone:{ required:true, isPhone:true, }, email:{ required:true, email:true, }, roleId:{ required:true, }, }, success: function(label) { //正确时的样式 label.text(" ").addClass("success"); }, messages: { userName: { required: "请输入用户名,3-16个字符(字母、数字、下划线),注册后不能更改", minlength: "用户名长度不能小于3个字符", maxlength: "用户名长度不能大于16个字符", remote: "用户名不可用" } }, onkeyup:false, focusCleanup:true, success:"valid" });