6-29 2,806 views
jQuery.validator.addMethod("check_user", function(value, element) {
var check = /^[A-Za-z\s]+$/;
//this.optional(element)如果元素为空并且不需要,则立即返回true。
return this.optional(element) || (check.test(value));
}, '必须是大小写字母或者空格');
rules: {
user: {
required: true,
maxlength: 15,
check_user:true,//自定义验证规则
},
}