jquery-validation-rails 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery-validation-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2012 Dan Ryan
2
+
3
+ jQuery Copyright (c)2012 jQuery Foundation and other contributors
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Jquery::Validation::Rails
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'jquery-validation-rails'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Add `jquery-validation-rails` to your Gemfile and run `bundle install`:
15
+
16
+ gem "jquery-validation-rails"
17
+
18
+ ### Include select2-rails javascript assets
19
+
20
+ Add the following to your `app/assets/javascripts/application.js`:
21
+
22
+ //= require jquery.validation
23
+ //= require jquery.validation.additional-methods
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ #encoding: utf-8
2
+
3
+ # -*- encoding: utf-8 -*-
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'jquery/validation/rails/version'
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = "jquery-validation-rails"
10
+ gem.version = Jquery::Validation::Rails::VERSION
11
+ gem.authors = ["Dan Ryan"]
12
+ gem.email = ["scriptfu@gmail.com"]
13
+ gem.description = %q{Integrate the jQuery Validation plugin into the Rails asset pipeline}
14
+ gem.summary = %q{This jQuery plugin makes simple clientside form validation trivial, while offering lots of option for customization. That makes a good choice if you’re building something new from scratch, but also when you’re trying to integrate it into an existing application with lots of existing markup. The plugin comes bundled with a useful set of validation methods, including URL and email validation, while providing an API to write your own methods. All bundled methods come with default error messages in english and translations into 36 locales.}
15
+ gem.homepage = ""
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+
22
+ gem.add_dependency "thor", "~> 0.14"
23
+ gem.add_development_dependency "bundler", "~> 1.0"
24
+ gem.add_development_dependency "rails", "~> 3.1"
25
+ end
@@ -0,0 +1 @@
1
+ require "jquery/validation/rails"
@@ -0,0 +1,10 @@
1
+ require 'jquery/validation/rails/version'
2
+ require 'jquery/validation/rails/engine'
3
+
4
+ module Jquery
5
+ module Validation
6
+ module Rails
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module Jquery
2
+ module Validation
3
+ module Rails
4
+ if defined?(::Rails) && ::Rails.version >= "3.1"
5
+ class Engine < ::Rails::Engine
6
+
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Validation
3
+ module Rails
4
+ VERSION = "1.10.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,433 @@
1
+ /*!
2
+ * jQuery Validation Plugin 1.10.0
3
+ *
4
+ * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
5
+ * http://docs.jquery.com/Plugins/Validation
6
+ *
7
+ * Copyright (c) 2006 - 2011 Jörn Zaefferer
8
+ *
9
+ * Dual licensed under the MIT and GPL licenses:
10
+ * http://www.opensource.org/licenses/mit-license.php
11
+ * http://www.gnu.org/licenses/gpl.html
12
+ */
13
+
14
+ (function() {
15
+
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."));
25
+
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."));
29
+
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."));
35
+
36
+ })();
37
+
38
+ jQuery.validator.addMethod("letterswithbasicpunc", function(value, element) {
39
+ return this.optional(element) || /^[a-z\-.,()'\"\s]+$/i.test(value);
40
+ }, "Letters or punctuation only please");
41
+
42
+ jQuery.validator.addMethod("alphanumeric", function(value, element) {
43
+ return this.optional(element) || /^\w+$/i.test(value);
44
+ }, "Letters, numbers, and underscores only please");
45
+
46
+ jQuery.validator.addMethod("lettersonly", function(value, element) {
47
+ return this.optional(element) || /^[a-z]+$/i.test(value);
48
+ }, "Letters only please");
49
+
50
+ jQuery.validator.addMethod("nowhitespace", function(value, element) {
51
+ return this.optional(element) || /^\S+$/i.test(value);
52
+ }, "No white space please");
53
+
54
+ jQuery.validator.addMethod("ziprange", function(value, element) {
55
+ return this.optional(element) || /^90[2-5]\d\{2\}-\d{4}$/.test(value);
56
+ }, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx");
57
+
58
+ jQuery.validator.addMethod("zipcodeUS", function(value, element) {
59
+ return this.optional(element) || /\d{5}-\d{4}$|^\d{5}$/.test(value)
60
+ }, "The specified US ZIP Code is invalid");
61
+
62
+ jQuery.validator.addMethod("integer", function(value, element) {
63
+ return this.optional(element) || /^-?\d+$/.test(value);
64
+ }, "A positive or negative non-decimal number please");
65
+
66
+ /**
67
+ * Return true, if the value is a valid vehicle identification number (VIN).
68
+ *
69
+ * Works with all kind of text inputs.
70
+ *
71
+ * @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
72
+ * @desc Declares a required input element whose value must be a valid vehicle identification number.
73
+ *
74
+ * @name jQuery.validator.methods.vinUS
75
+ * @type Boolean
76
+ * @cat Plugins/Validate/Methods
77
+ */
78
+ 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;
117
+ }, "The specified vehicle identification number (VIN) is invalid.");
118
+
119
+ /**
120
+ * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
121
+ *
122
+ * @example jQuery.validator.methods.date("01/01/1900")
123
+ * @result true
124
+ *
125
+ * @example jQuery.validator.methods.date("01/13/1990")
126
+ * @result false
127
+ *
128
+ * @example jQuery.validator.methods.date("01.01.1900")
129
+ * @result false
130
+ *
131
+ * @example <input name="pippo" class="{dateITA:true}" />
132
+ * @desc Declares an optional input element whose value must be a valid date.
133
+ *
134
+ * @name jQuery.validator.methods.dateITA
135
+ * @type Boolean
136
+ * @cat Plugins/Validate/Methods
137
+ */
138
+ 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;
154
+ }, "Please enter a correct date");
155
+
156
+ jQuery.validator.addMethod("dateNL", function(value, element) {
157
+ return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value);
158
+ }, "Vul hier een geldige datum in.");
159
+
160
+ jQuery.validator.addMethod("time", function(value, element) {
161
+ return this.optional(element) || /^([0-1]\d|2[0-3]):([0-5]\d)$/.test(value);
162
+ }, "Please enter a valid time, between 00:00 and 23:59");
163
+ 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");
166
+
167
+ /**
168
+ * matches US phone number format
169
+ *
170
+ * where the area code may not start with 1 and the prefix may not start with 1
171
+ * allows '-' or ' ' as a separator and allows parens around area code
172
+ * some people may want to put a '1' in front of their number
173
+ *
174
+ * 1(212)-999-2345 or
175
+ * 212 999 2344 or
176
+ * 212-999-0983
177
+ *
178
+ * but not
179
+ * 111-123-5434
180
+ * and not
181
+ * 212 123 4567
182
+ */
183
+ 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}$/);
187
+ }, "Please specify a valid phone number");
188
+
189
+ 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}))$/);
193
+ }, 'Please specify a valid phone number');
194
+
195
+ 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})$/);
199
+ }, 'Please specify a valid mobile number');
200
+
201
+ //Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
202
+ 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})))$/);
206
+ }, 'Please specify a valid uk phone number');
207
+ // On the above three UK functions, do the following server side processing:
208
+ // Compare with ^((?:00\s?|\+)(44)\s?)?\(?0?(?:\)\s?)?([1-9]\d{1,4}\)?[\d\s]+)
209
+ // Extract $2 and set $prefix to '+44<space>' if $2 is '44' otherwise set $prefix to '0'
210
+ // Extract $3 and remove spaces and parentheses. Phone number is combined $2 and $3.
211
+ // A number of very detailed GB telephone number RegEx patterns can also be found at:
212
+ // http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_UK_Telephone_Numbers
213
+
214
+ //Matches UK postcode. based on http://snipplr.com/view/3152/postcode-validation/
215
+ 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})$/);
218
+ }, 'Please specify a valid postcode');
219
+
220
+ // TODO check if value starts with <, otherwise don't try stripping anything
221
+ jQuery.validator.addMethod("strippedminlength", function(value, element, param) {
222
+ return jQuery(value).text().length >= param;
223
+ }, jQuery.validator.format("Please enter at least {0} characters"));
224
+
225
+ // same as email, but TLD is optional
226
+ 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);
228
+ }, jQuery.validator.messages.email);
229
+
230
+ // same as url, but TLD is optional
231
+ 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);
233
+ }, jQuery.validator.messages.url);
234
+
235
+ // NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
236
+ // Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
237
+ // Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
238
+ 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;
294
+ }, "Please enter a valid credit card number.");
295
+
296
+ 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);
298
+ }, "Please enter a valid IP v4 address.");
299
+
300
+ 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);
302
+ }, "Please enter a valid IP v6 address.");
303
+
304
+ /**
305
+ * Return true if the field value matches the given format RegExp
306
+ *
307
+ * @example jQuery.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)
308
+ * @result true
309
+ *
310
+ * @example jQuery.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)
311
+ * @result false
312
+ *
313
+ * @name jQuery.validator.methods.pattern
314
+ * @type Boolean
315
+ * @cat Plugins/Validate/Methods
316
+ */
317
+ 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);
325
+ }, "Invalid format.");
326
+
327
+
328
+ /*
329
+ * Lets you say "at least X inputs that match selector Y must be filled."
330
+ *
331
+ * The end result is that neither of these inputs:
332
+ *
333
+ * <input class="productinfo" name="partnumber">
334
+ * <input class="productinfo" name="description">
335
+ *
336
+ * ...will validate unless at least one of them is filled.
337
+ *
338
+ * partnumber: {require_from_group: [1,".productinfo"]},
339
+ * description: {require_from_group: [1,".productinfo"]}
340
+ *
341
+ */
342
+ 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;
356
+ }, jQuery.format("Please fill at least {0} of these fields."));
357
+
358
+ /*
359
+ * Lets you say "either at least X inputs that match selector Y must be filled,
360
+ * OR they must all be skipped (left blank)."
361
+ *
362
+ * The end result, is that none of these inputs:
363
+ *
364
+ * <input class="productinfo" name="partnumber">
365
+ * <input class="productinfo" name="description">
366
+ * <input class="productinfo" name="color">
367
+ *
368
+ * ...will validate unless either at least two of them are filled,
369
+ * OR none of them are.
370
+ *
371
+ * partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
372
+ * description: {skip_or_fill_minimum: [2,".productinfo"]},
373
+ * color: {skip_or_fill_minimum: [2,".productinfo"]}
374
+ *
375
+ */
376
+ 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;
393
+ }, jQuery.format("Please either skip these fields or fill at least {0} of them."));
394
+
395
+ // Accept a value from a file input based on a required mimetype
396
+ 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;
427
+ }, jQuery.format("Please enter a value with a valid mimetype."));
428
+
429
+ // Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept
430
+ 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."));