Jquery.Validate 扩展方法
- 包含空格在内的字符长度的限制
-
$.validator.addMethod('IncludeSpaceLength', function (value, element, maxlen) { if (maxlen > 0) { var remaining = (maxlen - (parseInt($(element).val().replace(/(\r\n|\n|\r)/gm, '\r\n').length))); if (remaining < 0) { return false; } } return true; }, $.validator.format("Please enter no more than {0} characters."));
- 电话号码的限制
-
$.validator.addMethod('TelephoneCheck', function (value, element) { return this.optional(element) || /^[0-9\-]+$/.test(value); }, $.validator.format("Invalid telephone number."));
引用格式为:
telephone: {
required: true,
TelephoneCheck: true,
IncludeSpaceLength: 30
},