方法一:
自从1.3.2版本开始,validateBox自身已经支持多重校验了,例如:
Box" data-options="required:true,validType:['email','length[0,20]']">
方法二:(不太好用,试了半天还是不显示第二个验证的消息)
对于1.5版本的easyui.min,注释掉以下代码:
然后再添加
Box.defaults.rules,{
multiple : {
validator : function(value,vtypes) {
var returnFlag = true;
var opts = $.fn.validateBox.defaults;
for (var i = 0; i < vtypes.length; i++) {
var methodinfo = /([a-zA-Z_]+)(.*)/.exec(vtypes[i]);
var rule = opts.rules[methodinfo[1]];
if (value && rule) {
var parame = eval(methodinfo[2]);
if (!rule["validator"](value,parame)) {
returnFlag = false;
this.message = rule.message;
break;
}
}
}
return returnFlag;
}
},length : {
validator : function(value,param) {
this.message = 'Please enter a value between {0} and {1}.';
var len = $.trim(value).length;
if (param) {
for (var i = 0; i < param.length; i++) {
this.message = this.message.replace(new RegExp(
"\\{" + i + "\\}","g"),param[i]);
}
}
return len >= param[0] && len <= param[1];
},message : 'Please enter a value between {0} and {1}.'
}
});
Box" data-options="required:true,validType:'multiple[\'email\',\'length[0,20]\']'">
方法三:(可以实现两种验证的消息)
= param[0];
},message : ''
}
});
根据方法三的试验:
//再次输入密码效验(与上一次一样;密码介于6-16位)
checkpwd: {
validator: function (value,param) {
var rules = $.fn.validatebox.defaults.rules;
rules.checkpwd.message = 'Please enter at least {0} characters.';
checkpwd: {
validator: function (value,param) {
var rules = $.fn.validatebox.defaults.rules;
rules.checkpwd.message = 'Please enter at least {0} characters.';
if (!rules.passequals.validator(value,param)) {
rules.checkpwd.message = rules.passequals.message;
return false;
}
if (!rules.minlength.validator(value)) {
rules.checkpwd.message = rules.minlength.message;
return false;
}
return value.length >= param[0];
},message: ''
},passequals: {
validator: function (value,param) {
return value == $(param[0]).val();
},message: '两次密码不一致.'
},minlength: {
validator: function (value) {
var len = $.trim(value).length;
return len >=6 && len <= 16;
},message: "输入内容长度必须介于6和16之间."
}
});
调用:(注意pwd两边不能写引号)