forked from victorjonsson/jQuery-Form-Validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
238 lines (199 loc) · 8.4 KB
/
example.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html>
<head>
<title>Form validator plugin for jQuery</title>
<meta charset="UTF-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.formvalidator.min.js"></script>
<link href="style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<h1>
Form validation using jQuery
</h1>
<p>
<a href="https://github.com/victorjonsson/jQuery-Form-Validator/">
https://github.com/victorjonsson/jQuery-Form-Validator/
</a>
</p>
<h2>
Basic concept
</h2>
<code>
<form onsubmit="return $(this).validate()"><br/>
<input data-validation="some_predefined_rule" /><br/>
...<br/>
</form>
</code>
<h2>Example of all features</h2>
<div class="section">
<form action="" onsubmit="if($(this).validate()) alert('Valid!'); return false;">
<p>
<strong>Required</strong> <em>required</em><br/>
<input data-validation="required"/>
</p>
<p>
<strong>Minimum length</strong> <em>validate_min_length length5</em><br/>
<input data-validation="validate_min_length length5"/>
</p>
<p>
<strong>Max length</strong> <em>validate_max_length length5</em><br/>
<textarea data-validation="validate_max_length length5" rows="4"></textarea>
</p>
<p>
<strong>Length between 3-5 characters</strong> <em>validate_length length3-5</em><br/>
<textarea data-validation="validate_length length3-5" rows="4"></textarea>
</p>
<p>
<strong>E-mail</strong> <em>validate_email</em><br/>
<input data-validation="validate_email"/>
</p>
<p>
<strong>Domain</strong> <em>validate_domain</em><br/>
<input data-validation="validate_domain"/>
</p>
<p>
<strong>Url</strong> <em>validate_url</em><br/>
<input data-validation="validate_url"/>
</p>
<p>
<strong>Float</strong> <em>validate_float</em><br/>
<input data-validation="validate_float"/>
</p>
<p>
<strong>Integer</strong> <em>validate_int</em><br/>
<input data-validation="validate_int"/>
</p>
<p>
<strong>Time HH:mm</strong> <em>validate_time</em><br/>
<input data-validation="validate_time"/>
</p>
<p>
<strong>Date yyyy-mm-dd</strong> (Custom date format is also possible) <em>validate_date</em><br/>
<input data-validation="validate_date"/>
</p>
<p>
<strong>Birthdate yyyy-mm-dd</strong> <em>validate_birthdate</em><br/>
<input data-validation="validate_birthdate"/>
</p>
<p>
<strong>Valid telephone number</strong> <em>validate_phone</em><br/>
<input data-validation="validate_phone"/>
</p>
<p>
<strong>Valid Swedish mobile telephone number</strong> <em>validate_swemobile</em><br/>
<input data-validation="validate_swemobile"/>
</p>
<p>
<strong>Valid Swedish social security number yyyymmddXXXX</strong> <em>validate_swesc</em><br/>
<input data-validation="validate_swesc"/>
</p>
<p>
<strong>UK VAT Number</strong> <em>validate_ukvatnumber</em><br/>
<input name="4" data-validation="validate_ukvatnumber"/>
</p>
<p>
<strong>Custom validation</strong>
<em>validate_custom regexp/^[a-z]{2} [0-9]{2}$/</em>
<input data-validation="validate_custom regexp/^[a-z]{2} [0-9]{2}$/"/>
</p>
<p>
<strong>Simple captcha, this field has to contain value "jqueryvalidation"</strong> <em>validate_spamcheck
captcha[VALUE-TO-VALIDATE]</em><br/>
<input data-validation="validate_spamcheck captchajqueryvalidation"/>
</p>
<p>
<strong>One of these radio buttons has to be checked</strong>
<em>required</em>
<br />
<input type="radio" data-validation="required" name="s1" value="0" /> Yes<br />
<input type="radio" name="s1" value="1" /> No<br />
<input type="radio" name="s1" value="2" /> Maybe
</p>
<p>
<strong>These two inputs has to have identical values (minimum 3 characters)</strong> <em>validate_confirmation length3</em><br/>
<input name="something" data-validation="validate_confirmation validate_min_length length3"/>
<input name="something_confirmation"/>
</p>
<p>
<strong>These features applies to select lists as well</strong>
<br />
<select name="whatever" data-validation="required">
<option value="">- - Select something - -</option>
<option value="1">Green</option>
<option value="2">Blue</option>
<option value="red">Red</option>
</select>
</p>
<p>
<strong>Length restriction</strong>
<span class="chars_left">
<span id="maxlength">50</span> characters left
</span>
<br/>
<textarea rows="4" id="area"></textarea>
</p>
<script type="text/javascript">
$('#area').restrictLength($('#maxlength'));
</script>
<p>
<input type="submit" value="Validate form"/>
</p>
</form>
</div>
<h2>
Customized example (no border color on error, different position on error messages, validate input value on blur)
</h2>
<div class="section">
<form action="" id="custom_form">
<p>
<strong>Length between 3-5 characters</strong> <em>validate_length length3-5</em><br/>
<textarea name="1" data-validation="validate_length length3-5" rows="4"></textarea>
</p>
<p>
<strong>E-mail</strong> <em>validate_email</em><br/>
<input name="2" data-validation="validate_email"/>
</p>
<p>
<strong>Domain</strong> <em>validate_domain</em><br/>
<input id="testing" name="3" data-help="No protocol is needed" data-validation="validate_domain"/>
</p>
<p>
<strong>Url</strong> <em>validate_url</em><br/>
<input name="4" data-validation="validate_url"/>
</p>
<p>
<strong>When will you arrive</strong>
<em>The answer given on the question below will only be validated if this option is unchecked</em>
<input type="checkbox" name="disable_hours" checked="checked"/>
</p>
<p>
<strong>Time HH:mm</strong> <em>validate_time</em><br/>
<input data-validation="validate_time" name="hours"/>
</p>
<p>
<input name="7" type="submit" value="Validate form"/>
</p>
</form>
<script>
var conf = {
errorMessagePosition : 'element',
borderColorOnError : '',
ignore: []
};
$('#custom_form')
.submit(function() {
conf.ignore.length = 0;
if ($('input[name=disable_hours]').is(':checked'))
conf.ignore.push('hours');
if ($(this).validate(false, conf))
alert('Valid!');
return false;
})
.validateOnBlur(false, conf)
.showHelpOnFocus();
</script>
</div>
</body>
</html>