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.10.0
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 (c) 2006 - 2011 Jörn Zaefferer
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
- function stripHtml(value) {
17
- // remove html tags and space chars
18
- return value.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' ')
19
- // remove punctuation
20
- .replace(/[.(),;:!?%#$'"_+=\/-]*/g,'');
21
- }
22
- jQuery.validator.addMethod("maxWords", function(value, element, params) {
23
- return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length <= params;
24
- }, jQuery.validator.format("Please enter {0} words or less."));
18
+ function stripHtml(value) {
19
+ // remove html tags and space chars
20
+ return value.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/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
- jQuery.validator.addMethod("minWords", function(value, element, params) {
27
- return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params;
28
- }, jQuery.validator.format("Please enter at least {0} words."));
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
- jQuery.validator.addMethod("rangeWords", function(value, element, params) {
31
- var valueStripped = stripHtml(value);
32
- var regex = /\b\w+\b/g;
33
- return this.optional(element) || valueStripped.match(regex).length >= params[0] && valueStripped.match(regex).length <= params[1];
34
- }, jQuery.validator.format("Please enter between {0} and {1} words."));
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
- return this.optional(element) || /^[a-z\-.,()'\"\s]+$/i.test(value);
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
- return this.optional(element) || /^\w+$/i.test(value);
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
- return this.optional(element) || /^[a-z]+$/i.test(value);
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
- return this.optional(element) || /^\S+$/i.test(value);
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
- return this.optional(element) || /^90[2-5]\d\{2\}-\d{4}$/.test(value);
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
- return this.optional(element) || /\d{5}-\d{4}$|^\d{5}$/.test(value)
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
- return this.optional(element) || /^-?\d+$/.test(value);
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
- if (v.length != 17) {
80
- return false;
81
- }
82
- var i, n, d, f, cd, cdv;
83
- 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"];
84
- 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];
85
- var FL = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];
86
- var rs = 0;
87
- for(i = 0; i < 17; i++){
88
- f = FL[i];
89
- d = v.slice(i,i+1);
90
- if (i == 8) {
91
- cdv = d;
92
- }
93
- if (!isNaN(d)) {
94
- d *= f;
95
- } else {
96
- for (n = 0; n < LL.length; n++) {
97
- if (d.toUpperCase() === LL[n]) {
98
- d = VL[n];
99
- d *= f;
100
- if (isNaN(cdv) && n == 8) {
101
- cdv = LL[n];
102
- }
103
- break;
104
- }
105
- }
106
- }
107
- rs += d;
108
- }
109
- cd = rs % 11;
110
- if (cd == 10) {
111
- cd = "X";
112
- }
113
- if (cd == cdv) {
114
- return true;
115
- }
116
- return false;
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
- var check = false;
140
- var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
141
- if( re.test(value)){
142
- var adata = value.split('/');
143
- var gg = parseInt(adata[0],10);
144
- var mm = parseInt(adata[1],10);
145
- var aaaa = parseInt(adata[2],10);
146
- var xdata = new Date(aaaa,mm-1,gg);
147
- if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) )
148
- check = true;
149
- else
150
- check = false;
151
- } else
152
- check = false;
153
- return this.optional(element) || check;
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
- return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value);
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
- return this.optional(element) || /^([0-1]\d|2[0-3]):([0-5]\d)$/.test(value);
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
- return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))$/i.test(value);
165
- }, "Please enter a valid time, between 00:00 am and 12:00 pm");
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
- phone_number = phone_number.replace(/\s+/g, "");
185
- return this.optional(element) || phone_number.length > 9 &&
186
- phone_number.match(/^(\+?1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
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
- phone_number = phone_number.replace(/\(|\)|\s+|-/g,'');
191
- return this.optional(element) || phone_number.length > 9 &&
192
- 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}))$/);
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
- phone_number = phone_number.replace(/\s+|-/g,'');
197
- return this.optional(element) || phone_number.length > 9 &&
198
- phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[45789]\d{2}|624)\s?\d{3}\s?\d{3})$/);
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
- phone_number = phone_number.replace(/\s+|-/g,'');
204
- return this.optional(element) || phone_number.length > 9 &&
205
- phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[45789]\d{8}|624\d{6})))$/);
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
- postcode = (postcode.toUpperCase()).replace(/\s+/g,'');
217
- 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})$/);
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
- return jQuery(value).text().length >= param;
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
- 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);
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
- 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);
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
- if (/[^0-9-]+/.test(value)) {
240
- return false;
241
- }
242
-
243
- value = value.replace(/\D/g, "");
244
-
245
- var validTypes = 0x0000;
246
-
247
- if (param.mastercard)
248
- validTypes |= 0x0001;
249
- if (param.visa)
250
- validTypes |= 0x0002;
251
- if (param.amex)
252
- validTypes |= 0x0004;
253
- if (param.dinersclub)
254
- validTypes |= 0x0008;
255
- if (param.enroute)
256
- validTypes |= 0x0010;
257
- if (param.discover)
258
- validTypes |= 0x0020;
259
- if (param.jcb)
260
- validTypes |= 0x0040;
261
- if (param.unknown)
262
- validTypes |= 0x0080;
263
- if (param.all)
264
- validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
265
-
266
- if (validTypes & 0x0001 && /^(5[12345])/.test(value)) { //mastercard
267
- return value.length == 16;
268
- }
269
- if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa
270
- return value.length == 16;
271
- }
272
- if (validTypes & 0x0004 && /^(3[47])/.test(value)) { //amex
273
- return value.length == 15;
274
- }
275
- if (validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test(value)) { //dinersclub
276
- return value.length == 14;
277
- }
278
- if (validTypes & 0x0010 && /^(2(014|149))/.test(value)) { //enroute
279
- return value.length == 15;
280
- }
281
- if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover
282
- return value.length == 16;
283
- }
284
- if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb
285
- return value.length == 16;
286
- }
287
- if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb
288
- return value.length == 15;
289
- }
290
- if (validTypes & 0x0080) { //unknown
291
- return true;
292
- }
293
- return false;
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
- 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);
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
- 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);
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
- if (this.optional(element)) {
319
- return true;
320
- }
321
- if (typeof param === 'string') {
322
- param = new RegExp('^(?:' + param + ')$');
323
- }
324
- return param.test(value);
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
- var validator = this;
344
- var selector = options[1];
345
- var validOrNot = $(selector, element.form).filter(function() {
346
- return validator.elementValue(this);
347
- }).length >= options[0];
348
-
349
- if(!$(element).data('being_validated')) {
350
- var fields = $(selector, element.form);
351
- fields.data('being_validated', true);
352
- fields.valid();
353
- fields.data('being_validated', false);
354
- }
355
- return validOrNot;
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
- var validator = this;
378
-
379
- numberRequired = options[0];
380
- selector = options[1];
381
- var numberFilled = $(selector, element.form).filter(function() {
382
- return validator.elementValue(this);
383
- }).length;
384
- var valid = numberFilled >= numberRequired || numberFilled === 0;
385
-
386
- if(!$(element).data('being_validated')) {
387
- var fields = $(selector, element.form);
388
- fields.data('being_validated', true);
389
- fields.valid();
390
- fields.data('being_validated', false);
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
- // Split mime on commas incase we have multiple types we can accept
398
- var typeParam = typeof param === "string" ? param.replace(/,/g, '|') : "image/*",
399
- optionalValue = this.optional(element),
400
- i, file;
401
-
402
- // Element is optional
403
- if(optionalValue) {
404
- return optionalValue;
405
- }
406
-
407
- if($(element).attr("type") === "file") {
408
- // If we are using a wildcard, make it regex friendly
409
- typeParam = typeParam.replace("*", ".*");
410
-
411
- // Check if the element has a FileList before checking each file
412
- if(element.files && element.files.length) {
413
- for(i = 0; i < element.files.length; i++) {
414
- file = element.files[i];
415
-
416
- // Grab the mimtype from the loaded file, verify it matches
417
- if(!file.type.match(new RegExp( ".?(" + typeParam + ")$", "i"))) {
418
- return false;
419
- }
420
- }
421
- }
422
- }
423
-
424
- // Either return true because we've validated each file, or because the
425
- // browser does not support element.files and the FileList feature
426
- return true;
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
- param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
432
- return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
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."));