rule: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z_@]{6,20}$/,
message: '只支持数字字母下划线,且不为纯数字或字母',
equalTo: 'password'
}, {// 手机
mobile: required,
rule: /^1[34578]d{9}$/,
message: '请输入有效的手机号码'
}, {// 验证码
code : required,
rule: /^d{6}$/,
message: '请输入6位数字验证码'
}, {// 邮箱
email : required,
rule: /^[A-Za-z0-9u4e00-u9fa5]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/,
message: '请输入正确的邮箱'
}
];
this.isCheckAll = false;
this.callback = callback;
// 合并参数
this._rules = this._rules.concat(params[1]);
if(params[2]) {
if(typeof params[2] == 'function') {
this.callback = params[2];
}else {// 提交表单时是否开启全部验证
this.isCheckAll = params[2];
}
}
// 用于存储合去重后的参数
this.rules = [];
}
Validator.prototype._getKey = function (obj) {
var k = '';
for(var key in obj) {
if(obj.hasOwnProperty(key)) {
if( key !== 'rule' && key !== 'message' && key !== 'equalTo') {
k = key;
}
}
}
return k;
};
/**
* 数组对象重复数据进行合并,后面的覆盖前面的
*/
Validator.prototype.filterRules = function (arrObj) {
var _this = this,
h = {},
res = [],
arrObject = this._rules;
$.each(arrObject, function (i, item) {
var k = _this._getKey(item);
try {
if(!h[k] && h[k] !== 0) {
h[k] = i;
res.push(item);
}else {
res[h[k]] = $.extend(res[h[k]], item);
}
}catch(e) {
throw new Error('不是必填')
}
});
this.rules = res;
};
Validator.prototype.check = function () {
var _this = this;
$.each(_this.rules, function (i, item) {
var key = _this._getKey(item),
reg = item.rule,
equalTo = item.equalTo,
errMsg = item.message;
_this.$el.find('[name='+key+']')
.on('blur', function () {
var $this = $(this),
errorMsg = '',
val = $this.val(),
ranges = reg.toString().match(/(d*,d*)/),
range = '',
min = 0,
max = 0,
placeholderTxt = $(this).attr("placeholder") ? $(this).attr("placeholder") : '信息';
// 定义错误提示信息
if(val && val != 'undefined') { // 值不为空
if(ranges) { // 边界限定
range = ranges[0];










