/**
|
* 校验数据 testVal
|
*
|
* @param {[Number,String]} val [val description]
|
* @param {[Object]} option [option description]
|
*
|
* @return {[Object]} [return description]
|
*/
|
function testVal(rules, val, callback, option, context, nameSpace) {
|
let result = {
|
code: 1,
|
// msg: option.msg
|
};
|
nameSpace = nameSpace || 'rule';
|
let msg = context.$t(nameSpace + '.' + option.msg);
|
|
// 根据正则验证数据
|
result.code = option.pattern.test(val)?1:0;
|
if(result.code == 1 && option.regVal) {
|
let min = option.min;
|
let max =option.max;
|
if(min > val || max < val) {
|
result.code = 0;
|
}
|
}
|
|
if(result.code == 0) {
|
callback(new Error(msg));
|
}else {
|
callback()
|
}
|
}
|
|
export default testVal;
|