引入jQuery-1.7.1.js和jquery.validate.js两个js文件
jquery.validate.js下载地址:http://xiazai.jb51.net/201703/yuanma/jquery.validate.rar
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery-1.7.1.js"></script>
<script src="Scripts/jquery.validate.js"></script>
<script>
$().ready(function () {
///自定义ajax验证
jQuery.validator.addMethod("ExistsCompany", function (value, element) { //用jquery ajax的方法验证电话是不是已存在
var flag = 1;
$.ajax({
type: "POST",
url: '/CustomerMonkey/ExistsCompanyAction',
async: false,
data: {
'name': value, "monkeyid": GetQueryString("monkeyid"), "customerid": function () {
return $("#hidCustomerID").val();
}
},
success: function (data) {
if (data.result == "TRUE") {
flag = 0;
}
else if (data.result == "NO") {
compaymsg = "Name does not exist";
}
}
});
if (flag == 0) {
return true;
} else {
return false;
}
}, compaymsg);
$("#form1").validate({
rules: {
txtUserName:
{
required: true,
minlength: 6,
rangelength: [6, 20], //长度5-10之间
remote: {
url: "/admin/CheckName", //后台处理程序
type: "post", //数据发送方式
dataType: "json", //接受数据格式
data: { //要传递的数据
name: function () {
return $("#txtUserName").val();
}
}
},
ExistsCompany: true,
},
txtPassword: {
required: true,
minlength: 6,
rangelength: [6, 20], //长度5-10之间
password: true,
},
txtPwd: {
required: true,
equalTo: "#txtPassword",
minlength: 6,
rangelength: [5, 20], //长度5-10之间
password: true,
},
txtDisplayName: {
required: true,
minlength: 6,
rangelength: [6, 20], //长度5-10之间
},
txtAge: {
required: true,
digits: true,
min: 1,
max: 100










