-
Notifications
You must be signed in to change notification settings - Fork 53
/
index.html
129 lines (113 loc) · 3.51 KB
/
index.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>we-validator</title>
<style>
*{
padding: 0;
margin: 0;
}
form{
margin: 10px;
}
input{
margin: 10px 0;
padding: 10px 0;
text-indent: 10px;
border: 1px solid #eee;
font-size: 16px;
display: block;
width: 100%;
}
p{
color: red;
font-size: 12px;
margin-bottom: 20px;
}
button{
padding: 10px 0;
width: 100%;
border: 1px solid #eee;
}
</style>
</head>
<body>
<form id="submitForm">
<input type="text" name="username" placeholder="用户名" />
<p class="error-box" id="username"></p>
<input type="password" name="pwd" placeholder="密码" />
<p class="error-box" id="pwd"></p>
<input type="password" name="repeatPwd" placeholder="确认密码" />
<p class="error-box" id="repeatPwd"></p>
<input type="number" name="phoneno" placeholder="手机号" />
<p class="error-box" id="phoneno"></p>
<input type="text" name="str" placeholder="中文 1-4 位" />
<p class="error-box" id="str"></p>
<button id="submitButton" type="button">提交</button>
</form>
<script src="https://unpkg.com/jquery/dist/jquery.min.js"></script>
<script src="https://unpkg.com/form-serializer/dist/jquery.serialize-object.min.js"></script>
<script src="../../dist/we-validator.js"></script>
<script>
/**
* 注意:此demo比较简单,请结合实际项目修改
*/
var validatorInstance = new WeValidator({
multiCheck: true,
onMessage: function(data){
console.log('onMessage');
console.log(data);
for(var name in data){
$('#' + name).html(data[name].msg)
}
},
rules: {
username: {
required: true
},
pwd: {
required: true
},
repeatPwd: {
required: true,
equalTo: 'pwd'
},
phoneno: {
required: true,
mobile: true
},
str: {
rangeChinese: [1,4]
}
},
messages: {
username: {
required: '请输入用户名'
},
pwd: {
required: '请输入密码'
},
repeatPwd: {
required: '请输入确认密码',
equalTo: '两次密码不一致'
},
phoneno: {
required: '请输入手机号',
mobile: '手机号格式不正确'
}
}
});
// 提交
$('#submitButton').on('click', function(){
var data = $('#submitForm').serializeObject();
console.log(data)
$('.error-box').html('')
if (!validatorInstance.checkData(data)) return;
console.log('开始提交');
})
</script>
</body>
</html>