jquery-validation-rails 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,66 +1,68 @@
|
|
1
|
+
/*! jQuery Validation Plugin - v1.11.0 - 2/4/2013
|
2
|
+
* https://github.com/jzaefferer/jquery-validation
|
3
|
+
* Copyright (c) 2013 Jörn Zaefferer; Licensed MIT */
|
4
|
+
|
1
5
|
/*!
|
2
|
-
* jQuery Validation Plugin 1.
|
6
|
+
* jQuery Validation Plugin 1.11.0
|
3
7
|
*
|
4
8
|
* http://bassistance.de/jquery-plugins/jquery-plugin-validation/
|
5
9
|
* http://docs.jquery.com/Plugins/Validation
|
6
10
|
*
|
7
|
-
* Copyright
|
8
|
-
*
|
9
|
-
* Dual licensed under the MIT and GPL licenses:
|
11
|
+
* Copyright 2013 Jörn Zaefferer
|
12
|
+
* Released under the MIT license:
|
10
13
|
* http://www.opensource.org/licenses/mit-license.php
|
11
|
-
* http://www.gnu.org/licenses/gpl.html
|
12
14
|
*/
|
13
15
|
|
14
16
|
(function() {
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
function stripHtml(value) {
|
19
|
+
// remove html tags and space chars
|
20
|
+
return value.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' ')
|
21
|
+
// remove punctuation
|
22
|
+
.replace(/[.(),;:!?%#$'"_+=\/\-]*/g,'');
|
23
|
+
}
|
24
|
+
jQuery.validator.addMethod("maxWords", function(value, element, params) {
|
25
|
+
return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length <= params;
|
26
|
+
}, jQuery.validator.format("Please enter {0} words or less."));
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
jQuery.validator.addMethod("minWords", function(value, element, params) {
|
29
|
+
return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params;
|
30
|
+
}, jQuery.validator.format("Please enter at least {0} words."));
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
jQuery.validator.addMethod("rangeWords", function(value, element, params) {
|
33
|
+
var valueStripped = stripHtml(value);
|
34
|
+
var regex = /\b\w+\b/g;
|
35
|
+
return this.optional(element) || valueStripped.match(regex).length >= params[0] && valueStripped.match(regex).length <= params[1];
|
36
|
+
}, jQuery.validator.format("Please enter between {0} and {1} words."));
|
35
37
|
|
36
|
-
}
|
38
|
+
}());
|
37
39
|
|
38
40
|
jQuery.validator.addMethod("letterswithbasicpunc", function(value, element) {
|
39
|
-
|
41
|
+
return this.optional(element) || /^[a-z\-.,()'"\s]+$/i.test(value);
|
40
42
|
}, "Letters or punctuation only please");
|
41
43
|
|
42
44
|
jQuery.validator.addMethod("alphanumeric", function(value, element) {
|
43
|
-
|
45
|
+
return this.optional(element) || /^\w+$/i.test(value);
|
44
46
|
}, "Letters, numbers, and underscores only please");
|
45
47
|
|
46
48
|
jQuery.validator.addMethod("lettersonly", function(value, element) {
|
47
|
-
|
49
|
+
return this.optional(element) || /^[a-z]+$/i.test(value);
|
48
50
|
}, "Letters only please");
|
49
51
|
|
50
52
|
jQuery.validator.addMethod("nowhitespace", function(value, element) {
|
51
|
-
|
53
|
+
return this.optional(element) || /^\S+$/i.test(value);
|
52
54
|
}, "No white space please");
|
53
55
|
|
54
56
|
jQuery.validator.addMethod("ziprange", function(value, element) {
|
55
|
-
|
57
|
+
return this.optional(element) || /^90[2-5]\d\{2\}-\d{4}$/.test(value);
|
56
58
|
}, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx");
|
57
59
|
|
58
60
|
jQuery.validator.addMethod("zipcodeUS", function(value, element) {
|
59
|
-
|
61
|
+
return this.optional(element) || /\d{5}-\d{4}$|^\d{5}$/.test(value);
|
60
62
|
}, "The specified US ZIP Code is invalid");
|
61
63
|
|
62
64
|
jQuery.validator.addMethod("integer", function(value, element) {
|
63
|
-
|
65
|
+
return this.optional(element) || /^-?\d+$/.test(value);
|
64
66
|
}, "A positive or negative non-decimal number please");
|
65
67
|
|
66
68
|
/**
|
@@ -76,44 +78,44 @@ jQuery.validator.addMethod("integer", function(value, element) {
|
|
76
78
|
* @cat Plugins/Validate/Methods
|
77
79
|
*/
|
78
80
|
jQuery.validator.addMethod("vinUS", function(v) {
|
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
|
-
|
81
|
+
if (v.length !== 17) {
|
82
|
+
return false;
|
83
|
+
}
|
84
|
+
var i, n, d, f, cd, cdv;
|
85
|
+
var LL = ["A","B","C","D","E","F","G","H","J","K","L","M","N","P","R","S","T","U","V","W","X","Y","Z"];
|
86
|
+
var VL = [1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9];
|
87
|
+
var FL = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];
|
88
|
+
var rs = 0;
|
89
|
+
for(i = 0; i < 17; i++){
|
90
|
+
f = FL[i];
|
91
|
+
d = v.slice(i,i+1);
|
92
|
+
if (i === 8) {
|
93
|
+
cdv = d;
|
94
|
+
}
|
95
|
+
if (!isNaN(d)) {
|
96
|
+
d *= f;
|
97
|
+
} else {
|
98
|
+
for (n = 0; n < LL.length; n++) {
|
99
|
+
if (d.toUpperCase() === LL[n]) {
|
100
|
+
d = VL[n];
|
101
|
+
d *= f;
|
102
|
+
if (isNaN(cdv) && n === 8) {
|
103
|
+
cdv = LL[n];
|
104
|
+
}
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
rs += d;
|
110
|
+
}
|
111
|
+
cd = rs % 11;
|
112
|
+
if (cd === 10) {
|
113
|
+
cd = "X";
|
114
|
+
}
|
115
|
+
if (cd === cdv) {
|
116
|
+
return true;
|
117
|
+
}
|
118
|
+
return false;
|
117
119
|
}, "The specified vehicle identification number (VIN) is invalid.");
|
118
120
|
|
119
121
|
/**
|
@@ -136,33 +138,35 @@ jQuery.validator.addMethod("vinUS", function(v) {
|
|
136
138
|
* @cat Plugins/Validate/Methods
|
137
139
|
*/
|
138
140
|
jQuery.validator.addMethod("dateITA", function(value, element) {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
141
|
+
var check = false;
|
142
|
+
var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
|
143
|
+
if( re.test(value)) {
|
144
|
+
var adata = value.split('/');
|
145
|
+
var gg = parseInt(adata[0],10);
|
146
|
+
var mm = parseInt(adata[1],10);
|
147
|
+
var aaaa = parseInt(adata[2],10);
|
148
|
+
var xdata = new Date(aaaa,mm-1,gg);
|
149
|
+
if ( ( xdata.getFullYear() === aaaa ) && ( xdata.getMonth() === mm - 1 ) && ( xdata.getDate() === gg ) ){
|
150
|
+
check = true;
|
151
|
+
} else {
|
152
|
+
check = false;
|
153
|
+
}
|
154
|
+
} else {
|
155
|
+
check = false;
|
156
|
+
}
|
157
|
+
return this.optional(element) || check;
|
154
158
|
}, "Please enter a correct date");
|
155
159
|
|
156
160
|
jQuery.validator.addMethod("dateNL", function(value, element) {
|
157
|
-
|
161
|
+
return this.optional(element) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(value);
|
158
162
|
}, "Vul hier een geldige datum in.");
|
159
163
|
|
160
164
|
jQuery.validator.addMethod("time", function(value, element) {
|
161
|
-
|
165
|
+
return this.optional(element) || /^([01]\d|2[0-3])(:[0-5]\d){1,2}$/.test(value);
|
162
166
|
}, "Please enter a valid time, between 00:00 and 23:59");
|
163
167
|
jQuery.validator.addMethod("time12h", function(value, element) {
|
164
|
-
|
165
|
-
}, "Please enter a valid time
|
168
|
+
return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}( ?[AP]M))$/i.test(value);
|
169
|
+
}, "Please enter a valid time in 12-hour format");
|
166
170
|
|
167
171
|
/**
|
168
172
|
* matches US phone number format
|
@@ -181,28 +185,28 @@ jQuery.validator.addMethod("time12h", function(value, element) {
|
|
181
185
|
* 212 123 4567
|
182
186
|
*/
|
183
187
|
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
|
184
|
-
|
185
|
-
|
186
|
-
|
188
|
+
phone_number = phone_number.replace(/\s+/g, "");
|
189
|
+
return this.optional(element) || phone_number.length > 9 &&
|
190
|
+
phone_number.match(/^(\+?1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
|
187
191
|
}, "Please specify a valid phone number");
|
188
192
|
|
189
193
|
jQuery.validator.addMethod('phoneUK', function(phone_number, element) {
|
190
|
-
|
191
|
-
|
192
|
-
|
194
|
+
phone_number = phone_number.replace(/\(|\)|\s+|-/g,'');
|
195
|
+
return this.optional(element) || phone_number.length > 9 &&
|
196
|
+
phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:(?:\d{5}\)?\s?\d{4,5})|(?:\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3}))|(?:\d{3}\)?\s?\d{3}\s?\d{3,4})|(?:\d{2}\)?\s?\d{4}\s?\d{4}))$/);
|
193
197
|
}, 'Please specify a valid phone number');
|
194
198
|
|
195
199
|
jQuery.validator.addMethod('mobileUK', function(phone_number, element) {
|
196
|
-
|
197
|
-
|
198
|
-
|
200
|
+
phone_number = phone_number.replace(/\s+|-/g,'');
|
201
|
+
return this.optional(element) || phone_number.length > 9 &&
|
202
|
+
phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[45789]\d{2}|624)\s?\d{3}\s?\d{3})$/);
|
199
203
|
}, 'Please specify a valid mobile number');
|
200
204
|
|
201
205
|
//Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
|
202
206
|
jQuery.validator.addMethod('phonesUK', function(phone_number, element) {
|
203
|
-
|
204
|
-
|
205
|
-
|
207
|
+
phone_number = phone_number.replace(/\s+|-/g,'');
|
208
|
+
return this.optional(element) || phone_number.length > 9 &&
|
209
|
+
phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[45789]\d{8}|624\d{6})))$/);
|
206
210
|
}, 'Please specify a valid uk phone number');
|
207
211
|
// On the above three UK functions, do the following server side processing:
|
208
212
|
// Compare with ^((?:00\s?|\+)(44)\s?)?\(?0?(?:\)\s?)?([1-9]\d{1,4}\)?[\d\s]+)
|
@@ -213,92 +217,100 @@ jQuery.validator.addMethod('phonesUK', function(phone_number, element) {
|
|
213
217
|
|
214
218
|
//Matches UK postcode. based on http://snipplr.com/view/3152/postcode-validation/
|
215
219
|
jQuery.validator.addMethod('postcodeUK', function(postcode, element) {
|
216
|
-
|
217
|
-
|
220
|
+
postcode = (postcode.toUpperCase()).replace(/\s+/g,'');
|
221
|
+
return this.optional(element) || postcode.match(/^([^QZ][^IJZ]{0,1}\d{1,2})(\d[^CIKMOV]{2})$/) || postcode.match(/^([^QV]\d[ABCDEFGHJKSTUW])(\d[^CIKMOV]{2})$/) || postcode.match(/^([^QV][^IJZ]\d[ABEHMNPRVWXY])(\d[^CIKMOV]{2})$/) || postcode.match(/^(GIR)(0AA)$/) || postcode.match(/^(BFPO)(\d{1,4})$/) || postcode.match(/^(BFPO)(C\/O\d{1,3})$/);
|
218
222
|
}, 'Please specify a valid postcode');
|
219
223
|
|
220
224
|
// TODO check if value starts with <, otherwise don't try stripping anything
|
221
225
|
jQuery.validator.addMethod("strippedminlength", function(value, element, param) {
|
222
|
-
|
226
|
+
return jQuery(value).text().length >= param;
|
223
227
|
}, jQuery.validator.format("Please enter at least {0} characters"));
|
224
228
|
|
225
229
|
// same as email, but TLD is optional
|
226
230
|
jQuery.validator.addMethod("email2", function(value, element, param) {
|
227
|
-
|
231
|
+
return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
|
228
232
|
}, jQuery.validator.messages.email);
|
229
233
|
|
230
234
|
// same as url, but TLD is optional
|
231
235
|
jQuery.validator.addMethod("url2", function(value, element, param) {
|
232
|
-
|
236
|
+
return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
|
233
237
|
}, jQuery.validator.messages.url);
|
234
238
|
|
235
239
|
// NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
|
236
240
|
// Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
|
237
241
|
// Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
|
238
242
|
jQuery.validator.addMethod("creditcardtypes", function(value, element, param) {
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
243
|
+
if (/[^0-9\-]+/.test(value)) {
|
244
|
+
return false;
|
245
|
+
}
|
246
|
+
|
247
|
+
value = value.replace(/\D/g, "");
|
248
|
+
|
249
|
+
var validTypes = 0x0000;
|
250
|
+
|
251
|
+
if (param.mastercard) {
|
252
|
+
validTypes |= 0x0001;
|
253
|
+
}
|
254
|
+
if (param.visa) {
|
255
|
+
validTypes |= 0x0002;
|
256
|
+
}
|
257
|
+
if (param.amex) {
|
258
|
+
validTypes |= 0x0004;
|
259
|
+
}
|
260
|
+
if (param.dinersclub) {
|
261
|
+
validTypes |= 0x0008;
|
262
|
+
}
|
263
|
+
if (param.enroute) {
|
264
|
+
validTypes |= 0x0010;
|
265
|
+
}
|
266
|
+
if (param.discover) {
|
267
|
+
validTypes |= 0x0020;
|
268
|
+
}
|
269
|
+
if (param.jcb) {
|
270
|
+
validTypes |= 0x0040;
|
271
|
+
}
|
272
|
+
if (param.unknown) {
|
273
|
+
validTypes |= 0x0080;
|
274
|
+
}
|
275
|
+
if (param.all) {
|
276
|
+
validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
|
277
|
+
}
|
278
|
+
if (validTypes & 0x0001 && /^(5[12345])/.test(value)) { //mastercard
|
279
|
+
return value.length === 16;
|
280
|
+
}
|
281
|
+
if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa
|
282
|
+
return value.length === 16;
|
283
|
+
}
|
284
|
+
if (validTypes & 0x0004 && /^(3[47])/.test(value)) { //amex
|
285
|
+
return value.length === 15;
|
286
|
+
}
|
287
|
+
if (validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test(value)) { //dinersclub
|
288
|
+
return value.length === 14;
|
289
|
+
}
|
290
|
+
if (validTypes & 0x0010 && /^(2(014|149))/.test(value)) { //enroute
|
291
|
+
return value.length === 15;
|
292
|
+
}
|
293
|
+
if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover
|
294
|
+
return value.length === 16;
|
295
|
+
}
|
296
|
+
if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb
|
297
|
+
return value.length === 16;
|
298
|
+
}
|
299
|
+
if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb
|
300
|
+
return value.length === 15;
|
301
|
+
}
|
302
|
+
if (validTypes & 0x0080) { //unknown
|
303
|
+
return true;
|
304
|
+
}
|
305
|
+
return false;
|
294
306
|
}, "Please enter a valid credit card number.");
|
295
307
|
|
296
308
|
jQuery.validator.addMethod("ipv4", function(value, element, param) {
|
297
|
-
|
309
|
+
return this.optional(element) || /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(value);
|
298
310
|
}, "Please enter a valid IP v4 address.");
|
299
311
|
|
300
312
|
jQuery.validator.addMethod("ipv6", function(value, element, param) {
|
301
|
-
|
313
|
+
return this.optional(element) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(value);
|
302
314
|
}, "Please enter a valid IP v6 address.");
|
303
315
|
|
304
316
|
/**
|
@@ -315,13 +327,13 @@ jQuery.validator.addMethod("ipv6", function(value, element, param) {
|
|
315
327
|
* @cat Plugins/Validate/Methods
|
316
328
|
*/
|
317
329
|
jQuery.validator.addMethod("pattern", function(value, element, param) {
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
330
|
+
if (this.optional(element)) {
|
331
|
+
return true;
|
332
|
+
}
|
333
|
+
if (typeof param === 'string') {
|
334
|
+
param = new RegExp('^(?:' + param + ')$');
|
335
|
+
}
|
336
|
+
return param.test(value);
|
325
337
|
}, "Invalid format.");
|
326
338
|
|
327
339
|
|
@@ -340,19 +352,19 @@ jQuery.validator.addMethod("pattern", function(value, element, param) {
|
|
340
352
|
*
|
341
353
|
*/
|
342
354
|
jQuery.validator.addMethod("require_from_group", function(value, element, options) {
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
355
|
+
var validator = this;
|
356
|
+
var selector = options[1];
|
357
|
+
var validOrNot = $(selector, element.form).filter(function() {
|
358
|
+
return validator.elementValue(this);
|
359
|
+
}).length >= options[0];
|
360
|
+
|
361
|
+
if(!$(element).data('being_validated')) {
|
362
|
+
var fields = $(selector, element.form);
|
363
|
+
fields.data('being_validated', true);
|
364
|
+
fields.valid();
|
365
|
+
fields.data('being_validated', false);
|
366
|
+
}
|
367
|
+
return validOrNot;
|
356
368
|
}, jQuery.format("Please fill at least {0} of these fields."));
|
357
369
|
|
358
370
|
/*
|
@@ -374,60 +386,59 @@ jQuery.validator.addMethod("require_from_group", function(value, element, option
|
|
374
386
|
*
|
375
387
|
*/
|
376
388
|
jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
return valid;
|
389
|
+
var validator = this;
|
390
|
+
var numberRequired = options[0];
|
391
|
+
var selector = options[1];
|
392
|
+
var numberFilled = $(selector, element.form).filter(function() {
|
393
|
+
return validator.elementValue(this);
|
394
|
+
}).length;
|
395
|
+
var valid = numberFilled >= numberRequired || numberFilled === 0;
|
396
|
+
|
397
|
+
if(!$(element).data('being_validated')) {
|
398
|
+
var fields = $(selector, element.form);
|
399
|
+
fields.data('being_validated', true);
|
400
|
+
fields.valid();
|
401
|
+
fields.data('being_validated', false);
|
402
|
+
}
|
403
|
+
return valid;
|
393
404
|
}, jQuery.format("Please either skip these fields or fill at least {0} of them."));
|
394
405
|
|
395
406
|
// Accept a value from a file input based on a required mimetype
|
396
407
|
jQuery.validator.addMethod("accept", function(value, element, param) {
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
408
|
+
// Split mime on commas in case we have multiple types we can accept
|
409
|
+
var typeParam = typeof param === "string" ? param.replace(/\s/g, '').replace(/,/g, '|') : "image/*",
|
410
|
+
optionalValue = this.optional(element),
|
411
|
+
i, file;
|
412
|
+
|
413
|
+
// Element is optional
|
414
|
+
if (optionalValue) {
|
415
|
+
return optionalValue;
|
416
|
+
}
|
417
|
+
|
418
|
+
if ($(element).attr("type") === "file") {
|
419
|
+
// If we are using a wildcard, make it regex friendly
|
420
|
+
typeParam = typeParam.replace(/\*/g, ".*");
|
421
|
+
|
422
|
+
// Check if the element has a FileList before checking each file
|
423
|
+
if (element.files && element.files.length) {
|
424
|
+
for (i = 0; i < element.files.length; i++) {
|
425
|
+
file = element.files[i];
|
426
|
+
|
427
|
+
// Grab the mimtype from the loaded file, verify it matches
|
428
|
+
if (!file.type.match(new RegExp( ".?(" + typeParam + ")$", "i"))) {
|
429
|
+
return false;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
}
|
433
|
+
}
|
434
|
+
|
435
|
+
// Either return true because we've validated each file, or because the
|
436
|
+
// browser does not support element.files and the FileList feature
|
437
|
+
return true;
|
427
438
|
}, jQuery.format("Please enter a value with a valid mimetype."));
|
428
439
|
|
429
440
|
// Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept
|
430
441
|
jQuery.validator.addMethod("extension", function(value, element, param) {
|
431
|
-
|
432
|
-
|
433
|
-
}, jQuery.format("Please enter a value with a valid extension."));
|
442
|
+
param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
|
443
|
+
return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
|
444
|
+
}, jQuery.format("Please enter a value with a valid extension."));
|