jquery validate验证方法
jQuery.validator.addMethod("stringCheck", function(value, element) { // return this.optional(element) || /^[0-9a-zA-Z_]{1,}$/.test(value); return this.optional(element) || /^[a-zA-Z]+[a-zA-Z0-9]+$/.test(value); }, "只能由英文字母或数字组成(不支持中文、不能以数字开头)"); // }, "只能包括英文字母、数字和下划线"); jQuery.validator.addMethod("mobile", function (value, element, param) { var pattern = /^\d+$/; return this.optional(element) || pattern.test(value); }, '只能输入数字'); //表单验证 $('#registerbox').validate({ rules: { UserName: { required: true, stringCheck: true, minlength: "3", maxlength: "15", cache: false, remote: { type: 'get', url: "/Account/Validate", dataType: 'json', data: { str: function () { return $("#username").val(); } } }, onkeyup: false }, Password: { required: true, }, Pwd_s: { required: true, equalTo: "#pass" }, Email: { required: true, email: true, cache: false, remote: { type: 'get', url: "/Account/Validate", dataType: 'json', data: { str: function () { return $("#userEmail").val(); } } } }, MemberType: { required: true, }, Mobile: { required: true, minlength: "11", maxlength: "11", mobile: true, cache: false, number:true, remote: { type: 'get', url: "/Account/Validate", dataType: 'json', data: { str: function () { return $("#userPhone").val(); } } } }, rule: { required: true } }, messages: { UserName: { required: "用户名不能为空", stringCheck: "只能由英文字母或数字组成(不支持中文、不能以数字开头)", minlength: "请输入3-15个字节(一个中文字算2个字节)", maxlength: "请输入3-15个字节(一个中文字算2个字节)", remote:"该用户名已被注册" }, Password: { required: "密码不能为空", }, Pwd_s: { required: "确认密码不能为空", equalTo: "两次密码不一样" }, MemberType: { required: "选择用户类型", }, Email: { required: "Email不能为空", email: "请输入正确的Email地址", remote: "该邮箱已被注册" }, Mobile: { required: "手机不能为空", minlength: "请输入11位手机号码", maxlength: "请输入11位手机号码", mobile: "只能输入数字", remote: "该手机已被注册" }, rule: "未接受条款" } });
相关推荐
tztzyzyz 2020-07-20
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
83510998 2020-07-18
81463166 2020-07-17