he wei
2025-04-09 850af610b190eeabbd05eba3291fe359775676af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
 * 校验数据 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;