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
| /**
| * 校验数据
| *
| * @param {[Number,String]} val [val description]
| * @param {[Object]} option [option description]
| *
| * @return {[Object]} [return description]
| */
| function testVal(rules, val, callback, option) {
| let result = {
| code: 1,
| msg: 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(option.msg));
| }else {
| callback()
| }
| }
|
| export default testVal;
|
|