-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.html
57 lines (45 loc) · 1.32 KB
/
validation.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="./libs/js/main.js"></script>
<script type="text/javascript">
let data = {
name: 'aaaa',
age: 123,//'123'でもOK
email: 'sample@gmail.com'
};
data = {
name: '',
age: '',
email: ''
};
data = {
name: '',
age: 'aa',//これはOK
email: 'aaaa'
};
let rules = {
'name': 'required',
'age': 'required|integer',
'email': 'required|email',
};
let error_msg = {
"required.name": '名前が未入力です。',
"required.age": '年齢が未入力です。',
"integer.age": '年齢は数値で入力してください。',
"required.email": 'emailが未入力です。',
"email.email": '正しいemailを入力してください。',
}
let validation = new Validator(data, rules, error_msg);
console.log('エラーなしかいなか' + validation.passes());
console.table('全エラー出力');
console.table(validation.errors.all());
console.log('email エラーなしかいなか' + validation.errors.has('email'));
console.table('emailエラー出力');
console.table(validation.errors.get('email'));
</script>
<body>
<p>validationをconsoleでチェック</p>
</body>
</html>