form表单验证以及扩展验证方法

所需Js文件:

 

$.validator.addMethod("isMobile", function(value, element) { //自定义扩展方法

var length = value.length; 
var mobile = /^((\+?86)|(\(\+86\)))?(13[0123456789][0-9]{8}|15[0123456789][0-9]{8}|18[0123456789][0-9]{8}|17[0123456789][0-9]{8}|147[0-9]{8})$/; 
return this.optional(element) || (length == 11 && mobile.test(value)); 
}, "请正确填写您的手机号码");

var validateForm = $("#doctorAddForm").validate({//验证规则
rules: {
loginName: {
required: false,
remote: {
url: "/virtual/system/doctor/validate_repeat_loginname",
type: "post",
cache: false
}
},
name: "required",
/* birthday: "required", */
pwd: {
required: true,
minlength: 6
},
belongHospitalIds:"required",
tel: {
required: true,
remote: {
url: "/virtual/system/doctor/validate_repeat_phone",
type: "post",
cache: false
},
isMobile: true
},
email: {
required: false,
email: true
}
/* workDate: "required", */
/* department: "required", */
/* title: "required" */
},
messages: {
loginName:  {
required: "请输入登陆名",
remote: "登录名重复"
},
name: "请输入医生名",
/* birthday: "请选择医生生日", */
pwd: {
required: "请输入登陆密码",
minlength: "密码必须>=6位"
},
belongHospitalIds:"请选择所属医院",
tel: {
required: "请输入医生手机号",
remote: "该手机号码已被使用",
isMobile: "请输入正确的手机号"
},
email: "请输入正确的邮箱"
/* workDate: "请选择从业开始时间", */
/* department: "请选择科室", */
/* title: "请选择职称" */
}
});

你可能感兴趣的:(Java)