-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
92 lines (91 loc) · 1.84 KB
/
test.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="dist/validator.umd.js"></script>
<script type="module">
import zhCN from './locale/zh-CN.json' assert { type: 'json' }
const validator = window.validator.default
validator.localize(zhCN)
validator
.validate([
{
dataKey: 'name',
value: 'xuanmo',
rules: 'required|max:5'
},
{
dataKey: 'age',
value: 18,
required: true,
rules: 'max:8'
},
{
dataKey: 'scope',
value: '',
message: '局部校验规则失败',
validator() {
return false
}
},
{
dataKey: 'confirmed1',
value: '123456'
},
{
dataKey: 'confirmed2',
value: '1234562',
rules: 'confirmed:@confirmed1'
},
{
dataKey: 'minLength',
value: '12345678',
rules: 'min_length:8'
},
{
dataKey: 'length2',
value: ' 123456789',
rules: 'max_length:8'
},
{
matrix: true,
matrixId: 'matrixId',
value: {
columns: [
{
dataKey: 'column1',
label: '矩阵列 1',
rules: 'required|min_length:9'
},
{
dataKey: 'column2',
label: '矩阵列 2',
rules: 'confirmed:@column1'
}
],
data: [
{
rowId: 'a',
column2: '222value'
},
{
rowId: 'b',
column1: 22,
column2: 'xxx'
}
]
}
}
])
.then(() => {
console.log('校验通过')
})
.catch((error) => {
console.log(error)
})
</script>
</body>
</html>