Jquery验证插件 JqueryValidation 动态验证用户名等
可以参考:http://www.w3cschool.cc/jquery/jquery-plugin-validate.html
//form1 验证用户名
$("#form1").validate({
focusCleanup: false,
focusInvalid: false,
errorElement: "span",
errorClass: "sss",
errorPlacement: function (error, element) {
error.appendTo(element.next());
},
rules: {
TextUserName: {
required: true,
isCharlength6_12: true,
jszxolUserName: true,
remote: {
url: "../mobileApi.asmx/isExistsUserName",
type: "post",
dataType: "json",
async: false,//如果这里文本框填写完后直接快速点击按钮验证是否用户存在的话,此处最好写同步进行.
data: { user_name: function () { return $("#TextUserName").val(); } }
}
}
}, //rules
messages: {
TextUserName: {
required: "请输入用户名",
isCharlength6_12: "用户名为6-12位字符",
jszxolUserName: "以字母开头,长度在6-12之间",
remote: "用户名已存在"
}
}//messages
});
//form2 验证手机号
$("#form2").validate({
focusCleanup: false,
focusInvalid: false,
errorElement: "span",
errorClass: "sss",
errorPlacement: function (error, element) {
error.appendTo(element.next());
},
rules: {
TextUserPhone: {
required: true,
isMobile: true,
remote: {
url: "../mobileApi.asmx/isExistsPhone",
type: "post",
dataType: "json",
data: { mobile_number: function () { return $("#TextUserPhone").val(); } }
}
}
}, //rules
messages: {
TextUserPhone: {
required: "请输入手机号码",
isMobile: "手机号码不符合规范",
remote: "手机号码已存在"
}
}//messages
});