$('#formNewUser').validate({
rules: {
Name: {
checkPhoneq: true,
required: true,
maxlength: 20
},
LoginName: {
required: true,
maxlength: 20
},
Email: {
required: true,
email: true
},
Pwd: {
required: true,
maxlength:20
},
RoleId: {
required: true,
},
Dept: {
required: true,
},
RoleId: {
required: true,
},
CompanyId: {
required: true
}
},
messages: {
Name: {
// checkPhone: '电话',
required: '请输入姓名',
maxlength: '最多输入20个字符'
},
LoginName: {
required: '请输入账号',
maxlength: '最多输入20个字符'
},
Email: {
required: '请输入邮箱',
email: '邮箱地址不正确'
},
Pwd: {
required: '请输入密码',
maxlength: '最多输入20个字符'
},
RoleId: {
required: '请选择角色',
},
Dept: {
required: '请选择部门',
},
RoleId: {
required: '角色不能为空',
},
CompanyId: {
required: '请选择公司'
}
},
errorElement: 'span',
errorPlacement: function (error, element) {
error.addClass('invalid-feedback');
element.closest('.form-group').append(error);
},
highlight: function (element, errorClass, validClass) {
$(element).addClass('is-invalid');
},
unhighlight: function (element, errorClass, validClass) {
$(element).removeClass('is-invalid');
}
});
$.validator.addMethod("checkPhoneq", function (value, element, params) {
var checkPhoneq = /^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8}$/;
return this.optional(element) || (checkPhoneq.test(value));
}, "Please enter the right phone number.");