var errIcon = " "; $.validator.setDefaults({ highlight: function (element) { $(element).closest('.form-group').removeClass('has-success').addClass('has-error'); }, success: function (element) { element.closest('.form-group').removeClass('has-error').addClass('has-success'); }, errorElement: "span", errorPlacement: function (error, element) { if (element.is(":radio") || element.is(":checkbox")) { error.appendTo(element.parent().parent().parent()); } else { error.appendTo(element.parent()); } }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none" }); $(function () { jQuery.validator.addMethod("isMobile", function (value, element) { var regex = /^1[3-9]{1}\d{9}$/; return this.optional(element) || (regex.test(value)); }, "请输入正确的手机号码"); $.validator.addMethod("strongPwd", function (value, element, params) { return checkPwdStrong(value) }, "请输入与6-16位密码,同时包含大小写字母和数字"); })