-
Notifications
You must be signed in to change notification settings - Fork 0
/
playgroud.js
64 lines (54 loc) · 1.3 KB
/
playgroud.js
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
import {
Validator
} from './validator.js';
var rules = {
username: "required|min:5",
item: "accepted",
password: "required_if:username,abc|confirmed",
year: "between:5,10|Numeric",
obj: "object",
alpha: "alpha",
alpha_dash: "alpha_dash",
different: "different:username",
digits: "digits:4",
digits_between: "digits_between:3,5",
required_with: "required_with:username,ids",
required_without: "required_without:ff",
home: "url",
name: "upper:NAME"
};
var data = {
username: 'abc',
password: '55',
password_confirmation: '55',
year: 6,
obj: {},
accepted: 0,
alpha: "231fd",
alpha_dash: "343..",
different: "abc",
digits: 66679,
digits_between: 1234,
required_with: "df",
home: "http://www.baidu.com",
name: "NAME"
};
var customMessages = {
accepted: ":attribute 必须接受",
};
var attribute = {
"item": "条款"
}
var replacers = {
accepted: function (message, attribute, rule, parameters) {
return message;
},
}
var v = new Validator(data, rules, customMessages, attribute, replacers);
v.register('upper', (attribute, value, parameters) => {
return value.toUpperCase() == "NAME";
}, ":attribute = :value 不对");
if (v.fails()) {
console.log(v.messages());
}
console.log(v)