jquery-validation-rails 1.16.0 → 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/jquery-validation-rails.gemspec +11 -11
  4. data/lib/jquery/validation/rails/version.rb +1 -1
  5. data/vendor/assets/javascripts/jquery.validate.additional-methods.js +1015 -625
  6. data/vendor/assets/javascripts/jquery.validate.js +1610 -1534
  7. data/vendor/assets/javascripts/jquery.validate.localization/messages_ar.js +12 -0
  8. data/vendor/assets/javascripts/jquery.validate.localization/messages_az.js +12 -0
  9. data/vendor/assets/javascripts/jquery.validate.localization/messages_bg.js +13 -1
  10. data/vendor/assets/javascripts/jquery.validate.localization/messages_bn_BD.js +12 -0
  11. data/vendor/assets/javascripts/jquery.validate.localization/messages_ca.js +12 -0
  12. data/vendor/assets/javascripts/jquery.validate.localization/messages_cs.js +14 -1
  13. data/vendor/assets/javascripts/jquery.validate.localization/messages_da.js +30 -4
  14. data/vendor/assets/javascripts/jquery.validate.localization/messages_de.js +66 -4
  15. data/vendor/assets/javascripts/jquery.validate.localization/messages_el.js +12 -0
  16. data/vendor/assets/javascripts/jquery.validate.localization/messages_es.js +12 -0
  17. data/vendor/assets/javascripts/jquery.validate.localization/messages_es_AR.js +12 -0
  18. data/vendor/assets/javascripts/jquery.validate.localization/messages_es_PE.js +12 -0
  19. data/vendor/assets/javascripts/jquery.validate.localization/messages_et.js +12 -0
  20. data/vendor/assets/javascripts/jquery.validate.localization/messages_eu.js +12 -0
  21. data/vendor/assets/javascripts/jquery.validate.localization/messages_fa.js +19 -6
  22. data/vendor/assets/javascripts/jquery.validate.localization/messages_fi.js +12 -0
  23. data/vendor/assets/javascripts/jquery.validate.localization/messages_fr.js +15 -1
  24. data/vendor/assets/javascripts/jquery.validate.localization/messages_ge.js +12 -0
  25. data/vendor/assets/javascripts/jquery.validate.localization/messages_gl.js +12 -0
  26. data/vendor/assets/javascripts/jquery.validate.localization/messages_he.js +12 -0
  27. data/vendor/assets/javascripts/jquery.validate.localization/messages_hr.js +12 -0
  28. data/vendor/assets/javascripts/jquery.validate.localization/messages_hu.js +14 -1
  29. data/vendor/assets/javascripts/jquery.validate.localization/messages_hy_AM.js +12 -0
  30. data/vendor/assets/javascripts/jquery.validate.localization/messages_id.js +12 -0
  31. data/vendor/assets/javascripts/jquery.validate.localization/messages_is.js +12 -0
  32. data/vendor/assets/javascripts/jquery.validate.localization/messages_it.js +12 -0
  33. data/vendor/assets/javascripts/jquery.validate.localization/messages_ja.js +13 -0
  34. data/vendor/assets/javascripts/jquery.validate.localization/messages_ka.js +12 -0
  35. data/vendor/assets/javascripts/jquery.validate.localization/messages_kk.js +12 -0
  36. data/vendor/assets/javascripts/jquery.validate.localization/messages_ko.js +12 -0
  37. data/vendor/assets/javascripts/jquery.validate.localization/messages_lt.js +12 -0
  38. data/vendor/assets/javascripts/jquery.validate.localization/messages_lv.js +12 -0
  39. data/vendor/assets/javascripts/jquery.validate.localization/messages_mk.js +12 -0
  40. data/vendor/assets/javascripts/jquery.validate.localization/messages_my.js +12 -0
  41. data/vendor/assets/javascripts/jquery.validate.localization/messages_nl.js +13 -0
  42. data/vendor/assets/javascripts/jquery.validate.localization/messages_no.js +20 -8
  43. data/vendor/assets/javascripts/jquery.validate.localization/messages_pl.js +14 -0
  44. data/vendor/assets/javascripts/jquery.validate.localization/messages_pt_BR.js +31 -16
  45. data/vendor/assets/javascripts/jquery.validate.localization/messages_pt_PT.js +12 -0
  46. data/vendor/assets/javascripts/jquery.validate.localization/messages_ro.js +12 -0
  47. data/vendor/assets/javascripts/jquery.validate.localization/messages_ru.js +12 -0
  48. data/vendor/assets/javascripts/jquery.validate.localization/messages_sd.js +35 -0
  49. data/vendor/assets/javascripts/jquery.validate.localization/messages_si.js +12 -0
  50. data/vendor/assets/javascripts/jquery.validate.localization/messages_sk.js +14 -1
  51. data/vendor/assets/javascripts/jquery.validate.localization/messages_sl.js +12 -0
  52. data/vendor/assets/javascripts/jquery.validate.localization/messages_sr.js +12 -0
  53. data/vendor/assets/javascripts/jquery.validate.localization/messages_sr_lat.js +12 -0
  54. data/vendor/assets/javascripts/jquery.validate.localization/messages_sv.js +15 -1
  55. data/vendor/assets/javascripts/jquery.validate.localization/messages_th.js +12 -0
  56. data/vendor/assets/javascripts/jquery.validate.localization/messages_tj.js +12 -0
  57. data/vendor/assets/javascripts/jquery.validate.localization/messages_tr.js +13 -1
  58. data/vendor/assets/javascripts/jquery.validate.localization/messages_uk.js +12 -0
  59. data/vendor/assets/javascripts/jquery.validate.localization/messages_ur.js +12 -0
  60. data/vendor/assets/javascripts/jquery.validate.localization/messages_vi.js +13 -1
  61. data/vendor/assets/javascripts/jquery.validate.localization/messages_zh.js +13 -0
  62. data/vendor/assets/javascripts/jquery.validate.localization/messages_zh_TW.js +12 -0
  63. data/vendor/assets/javascripts/jquery.validate.localization/methods_de.js +12 -0
  64. data/vendor/assets/javascripts/jquery.validate.localization/methods_es_CL.js +12 -0
  65. data/vendor/assets/javascripts/jquery.validate.localization/methods_fi.js +12 -0
  66. data/vendor/assets/javascripts/jquery.validate.localization/methods_it.js +24 -0
  67. data/vendor/assets/javascripts/jquery.validate.localization/methods_nl.js +15 -0
  68. data/vendor/assets/javascripts/jquery.validate.localization/methods_pt.js +12 -0
  69. metadata +8 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5d7586d9f1c47ef2827aa63b8786ac34aba63c26
4
- data.tar.gz: f936c66cddbc44a7b82d57e8670e374b4e06e225
2
+ SHA256:
3
+ metadata.gz: 5c5c3f12a30de196e894ed0b762565b7f5586dd7be072110a699788d440f1454
4
+ data.tar.gz: de2580358ccc0fe520f2db82a49030fcc54cbcb896b3a094217e557bbe40e868
5
5
  SHA512:
6
- metadata.gz: 10c9662b8006b7ca9ddc10e48e8bafda38286135a7beae6c923ac990b8a0b5d41a5705cb0a42fb93ead905c3f91372f1cbf0ca4577aff5751198b0e792fa08e0
7
- data.tar.gz: 0bd49754d15a6c7255ba71225a3b4e52cb4f6b1831d02d0d753cb267107206b62d36908a346865be575b9875b3e31280e847767db68d1dc28957de5a2c2965ed
6
+ metadata.gz: 0af1a78001598b1970e525349737f0064e57e2acb2486bd3a65e9fa5c8c9c41b1f02afa22d675432ba3f7d42b79ddb07adcd0184d27ed13942a94f281eea8873
7
+ data.tar.gz: fdb8cadc40d7a0e1397b26363cf61c9d0e24344b66ca6c9c9c898f30fa9fb2e558f149c0d8256445127f5559c8b65d94908ba4e1fbbd4141e7a281189a37a01f
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  Add the following line to your project's `Gemfile`:
9
9
  ```rb
10
- gem 'jquery-validation-rails`
10
+ gem 'jquery-validation-rails'
11
11
  ```
12
12
 
13
13
  Run the following in your terminal:
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # -*- encoding: utf-8 -*-
4
4
  lib = File.expand_path('../lib', __FILE__)
@@ -6,16 +6,16 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
  require 'jquery/validation/rails/version'
7
7
 
8
8
  Gem::Specification.new do |gem|
9
- gem.name = "jquery-validation-rails"
9
+ gem.name = 'jquery-validation-rails'
10
10
  gem.version = Jquery::Validation::Rails::VERSION
11
- gem.authors = ["Dan Ryan"]
12
- gem.email = ["dan@appliedawesome.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 = "https://github.com/danryan/jquery-validation-rails"
16
- gem.license = "MIT"
17
- gem.files = `git ls-files`.split($/)
18
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.authors = ['Curt Howard, Dan Ryan']
12
+ gem.email = ['curt@meows.us']
13
+ gem.description = 'Integrate the jQuery Validation plugin into the Rails asset pipeline'
14
+ gem.summary = '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 = 'https://github.com/meowsus/jquery-validation-rails'
16
+ gem.license = 'MIT'
17
+ gem.files = `git ls-files`.split("\n")
18
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
19
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
- gem.require_paths = ["lib"]
20
+ gem.require_paths = ['lib']
21
21
  end
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Validation
3
3
  module Rails
4
- VERSION = '1.16.0'.freeze
4
+ VERSION = '1.19.0'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,92 +1,124 @@
1
1
  /*!
2
- * jQuery Validation Plugin v1.16.0
2
+ * jQuery Validation Plugin v1.19.0
3
3
  *
4
- * http://jqueryvalidation.org/
4
+ * https://jqueryvalidation.org/
5
5
  *
6
- * Copyright (c) 2016 Jörn Zaefferer
6
+ * Copyright (c) 2018 Jörn Zaefferer
7
7
  * Released under the MIT license
8
8
  */
9
9
  (function( factory ) {
10
- if ( typeof define === "function" && define.amd ) {
11
- define( ["jquery", "./jquery.validate"], factory );
12
- } else if (typeof module === "object" && module.exports) {
13
- module.exports = factory( require( "jquery" ) );
14
- } else {
15
- factory( jQuery );
16
- }
10
+ if ( typeof define === "function" && define.amd ) {
11
+ define( ["jquery", "./jquery.validate"], factory );
12
+ } else if (typeof module === "object" && module.exports) {
13
+ module.exports = factory( require( "jquery" ) );
14
+ } else {
15
+ factory( jQuery );
16
+ }
17
17
  }(function( $ ) {
18
18
 
19
19
  ( function() {
20
20
 
21
- function stripHtml( value ) {
21
+ function stripHtml( value ) {
22
22
 
23
- // Remove html tags and space chars
24
- return value.replace( /<.[^<>]*?>/g, " " ).replace( /&nbsp;|&#160;/gi, " " )
23
+ // Remove html tags and space chars
24
+ return value.replace( /<.[^<>]*?>/g, " " ).replace( /&nbsp;|&#160;/gi, " " )
25
25
 
26
- // Remove punctuation
27
- .replace( /[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "" );
28
- }
26
+ // Remove punctuation
27
+ .replace( /[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "" );
28
+ }
29
29
 
30
- $.validator.addMethod( "maxWords", function( value, element, params ) {
31
- return this.optional( element ) || stripHtml( value ).match( /\b\w+\b/g ).length <= params;
32
- }, $.validator.format( "Please enter {0} words or less." ) );
30
+ $.validator.addMethod( "maxWords", function( value, element, params ) {
31
+ return this.optional( element ) || stripHtml( value ).match( /\b\w+\b/g ).length <= params;
32
+ }, $.validator.format( "Please enter {0} words or less." ) );
33
33
 
34
- $.validator.addMethod( "minWords", function( value, element, params ) {
35
- return this.optional( element ) || stripHtml( value ).match( /\b\w+\b/g ).length >= params;
36
- }, $.validator.format( "Please enter at least {0} words." ) );
34
+ $.validator.addMethod( "minWords", function( value, element, params ) {
35
+ return this.optional( element ) || stripHtml( value ).match( /\b\w+\b/g ).length >= params;
36
+ }, $.validator.format( "Please enter at least {0} words." ) );
37
37
 
38
- $.validator.addMethod( "rangeWords", function( value, element, params ) {
39
- var valueStripped = stripHtml( value ),
40
- regex = /\b\w+\b/g;
41
- return this.optional( element ) || valueStripped.match( regex ).length >= params[ 0 ] && valueStripped.match( regex ).length <= params[ 1 ];
42
- }, $.validator.format( "Please enter between {0} and {1} words." ) );
38
+ $.validator.addMethod( "rangeWords", function( value, element, params ) {
39
+ var valueStripped = stripHtml( value ),
40
+ regex = /\b\w+\b/g;
41
+ return this.optional( element ) || valueStripped.match( regex ).length >= params[ 0 ] && valueStripped.match( regex ).length <= params[ 1 ];
42
+ }, $.validator.format( "Please enter between {0} and {1} words." ) );
43
43
 
44
44
  }() );
45
45
 
46
+ /**
47
+ * This is used in the United States to process payments, deposits,
48
+ * or transfers using the Automated Clearing House (ACH) or Fedwire
49
+ * systems. A very common use case would be to validate a form for
50
+ * an ACH bill payment.
51
+ */
52
+ $.validator.addMethod( "abaRoutingNumber", function( value ) {
53
+ var checksum = 0;
54
+ var tokens = value.split( "" );
55
+ var length = tokens.length;
56
+
57
+ // Length Check
58
+ if ( length !== 9 ) {
59
+ return false;
60
+ }
61
+
62
+ // Calc the checksum
63
+ // https://en.wikipedia.org/wiki/ABA_routing_transit_number
64
+ for ( var i = 0; i < length; i += 3 ) {
65
+ checksum += parseInt( tokens[ i ], 10 ) * 3 +
66
+ parseInt( tokens[ i + 1 ], 10 ) * 7 +
67
+ parseInt( tokens[ i + 2 ], 10 );
68
+ }
69
+
70
+ // If not zero and divisible by 10 then valid
71
+ if ( checksum !== 0 && checksum % 10 === 0 ) {
72
+ return true;
73
+ }
74
+
75
+ return false;
76
+ }, "Please enter a valid routing number." );
77
+
46
78
  // Accept a value from a file input based on a required mimetype
47
79
  $.validator.addMethod( "accept", function( value, element, param ) {
48
80
 
49
- // Split mime on commas in case we have multiple types we can accept
50
- var typeParam = typeof param === "string" ? param.replace( /\s/g, "" ) : "image/*",
51
- optionalValue = this.optional( element ),
52
- i, file, regex;
53
-
54
- // Element is optional
55
- if ( optionalValue ) {
56
- return optionalValue;
57
- }
58
-
59
- if ( $( element ).attr( "type" ) === "file" ) {
60
-
61
- // Escape string to be used in the regex
62
- // see: http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
63
- // Escape also "/*" as "/.*" as a wildcard
64
- typeParam = typeParam
65
- .replace( /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g, "\\$&" )
66
- .replace( /,/g, "|" )
67
- .replace( /\/\*/g, "/.*" );
68
-
69
- // Check if the element has a FileList before checking each file
70
- if ( element.files && element.files.length ) {
71
- regex = new RegExp( ".?(" + typeParam + ")$", "i" );
72
- for ( i = 0; i < element.files.length; i++ ) {
73
- file = element.files[ i ];
74
-
75
- // Grab the mimetype from the loaded file, verify it matches
76
- if ( !file.type.match( regex ) ) {
77
- return false;
78
- }
79
- }
80
- }
81
- }
82
-
83
- // Either return true because we've validated each file, or because the
84
- // browser does not support element.files and the FileList feature
85
- return true;
81
+ // Split mime on commas in case we have multiple types we can accept
82
+ var typeParam = typeof param === "string" ? param.replace( /\s/g, "" ) : "image/*",
83
+ optionalValue = this.optional( element ),
84
+ i, file, regex;
85
+
86
+ // Element is optional
87
+ if ( optionalValue ) {
88
+ return optionalValue;
89
+ }
90
+
91
+ if ( $( element ).attr( "type" ) === "file" ) {
92
+
93
+ // Escape string to be used in the regex
94
+ // see: https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
95
+ // Escape also "/*" as "/.*" as a wildcard
96
+ typeParam = typeParam
97
+ .replace( /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g, "\\$&" )
98
+ .replace( /,/g, "|" )
99
+ .replace( /\/\*/g, "/.*" );
100
+
101
+ // Check if the element has a FileList before checking each file
102
+ if ( element.files && element.files.length ) {
103
+ regex = new RegExp( ".?(" + typeParam + ")$", "i" );
104
+ for ( i = 0; i < element.files.length; i++ ) {
105
+ file = element.files[ i ];
106
+
107
+ // Grab the mimetype from the loaded file, verify it matches
108
+ if ( !file.type.match( regex ) ) {
109
+ return false;
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ // Either return true because we've validated each file, or because the
116
+ // browser does not support element.files and the FileList feature
117
+ return true;
86
118
  }, $.validator.format( "Please enter a value with a valid mimetype." ) );
87
119
 
88
120
  $.validator.addMethod( "alphanumeric", function( value, element ) {
89
- return this.optional( element ) || /^\w+$/i.test( value );
121
+ return this.optional( element ) || /^\w+$/i.test( value );
90
122
  }, "Letters, numbers, and underscores only please" );
91
123
 
92
124
  /*
@@ -96,30 +128,30 @@ $.validator.addMethod( "alphanumeric", function( value, element ) {
96
128
  * acceptable: 123456789 or 12 34 56 789
97
129
  */
98
130
  $.validator.addMethod( "bankaccountNL", function( value, element ) {
99
- if ( this.optional( element ) ) {
100
- return true;
101
- }
102
- if ( !( /^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test( value ) ) ) {
103
- return false;
104
- }
105
-
106
- // Now '11 check'
107
- var account = value.replace( / /g, "" ), // Remove spaces
108
- sum = 0,
109
- len = account.length,
110
- pos, factor, digit;
111
- for ( pos = 0; pos < len; pos++ ) {
112
- factor = len - pos;
113
- digit = account.substring( pos, pos + 1 );
114
- sum = sum + factor * digit;
115
- }
116
- return sum % 11 === 0;
131
+ if ( this.optional( element ) ) {
132
+ return true;
133
+ }
134
+ if ( !( /^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test( value ) ) ) {
135
+ return false;
136
+ }
137
+
138
+ // Now '11 check'
139
+ var account = value.replace( / /g, "" ), // Remove spaces
140
+ sum = 0,
141
+ len = account.length,
142
+ pos, factor, digit;
143
+ for ( pos = 0; pos < len; pos++ ) {
144
+ factor = len - pos;
145
+ digit = account.substring( pos, pos + 1 );
146
+ sum = sum + factor * digit;
147
+ }
148
+ return sum % 11 === 0;
117
149
  }, "Please specify a valid bank account number" );
118
150
 
119
151
  $.validator.addMethod( "bankorgiroaccountNL", function( value, element ) {
120
- return this.optional( element ) ||
121
- ( $.validator.methods.bankaccountNL.call( this, value, element ) ) ||
122
- ( $.validator.methods.giroaccountNL.call( this, value, element ) );
152
+ return this.optional( element ) ||
153
+ ( $.validator.methods.bankaccountNL.call( this, value, element ) ) ||
154
+ ( $.validator.methods.giroaccountNL.call( this, value, element ) );
123
155
  }, "Please specify a valid bank or giro account number" );
124
156
 
125
157
  /**
@@ -191,240 +223,371 @@ $.validator.addMethod( "bic", function( value, element ) {
191
223
  * S Letter
192
224
  *
193
225
  */
194
- $.validator.addMethod( "cifES", function( value ) {
195
- "use strict";
196
-
197
- var cifRegEx = new RegExp( /^([ABCDEFGHJKLMNPQRSUVW])(\d{7})([0-9A-J])$/gi );
198
- var letter = value.substring( 0, 1 ), // [ T ]
199
- number = value.substring( 1, 8 ), // [ P ][ P ][ N ][ N ][ N ][ N ][ N ]
200
- control = value.substring( 8, 9 ), // [ C ]
201
- all_sum = 0,
202
- even_sum = 0,
203
- odd_sum = 0,
204
- i, n,
205
- control_digit,
206
- control_letter;
207
-
208
- function isOdd( n ) {
209
- return n % 2 === 0;
210
- }
226
+ $.validator.addMethod( "cifES", function( value, element ) {
227
+ "use strict";
228
+
229
+ if ( this.optional( element ) ) {
230
+ return true;
231
+ }
232
+
233
+ var cifRegEx = new RegExp( /^([ABCDEFGHJKLMNPQRSUVW])(\d{7})([0-9A-J])$/gi );
234
+ var letter = value.substring( 0, 1 ), // [ T ]
235
+ number = value.substring( 1, 8 ), // [ P ][ P ][ N ][ N ][ N ][ N ][ N ]
236
+ control = value.substring( 8, 9 ), // [ C ]
237
+ all_sum = 0,
238
+ even_sum = 0,
239
+ odd_sum = 0,
240
+ i, n,
241
+ control_digit,
242
+ control_letter;
243
+
244
+ function isOdd( n ) {
245
+ return n % 2 === 0;
246
+ }
247
+
248
+ // Quick format test
249
+ if ( value.length !== 9 || !cifRegEx.test( value ) ) {
250
+ return false;
251
+ }
252
+
253
+ for ( i = 0; i < number.length; i++ ) {
254
+ n = parseInt( number[ i ], 10 );
255
+
256
+ // Odd positions
257
+ if ( isOdd( i ) ) {
258
+
259
+ // Odd positions are multiplied first.
260
+ n *= 2;
261
+
262
+ // If the multiplication is bigger than 10 we need to adjust
263
+ odd_sum += n < 10 ? n : n - 9;
264
+
265
+ // Even positions
266
+ // Just sum them
267
+ } else {
268
+ even_sum += n;
269
+ }
270
+ }
271
+
272
+ all_sum = even_sum + odd_sum;
273
+ control_digit = ( 10 - ( all_sum ).toString().substr( -1 ) ).toString();
274
+ control_digit = parseInt( control_digit, 10 ) > 9 ? "0" : control_digit;
275
+ control_letter = "JABCDEFGHI".substr( control_digit, 1 ).toString();
276
+
277
+ // Control must be a digit
278
+ if ( letter.match( /[ABEH]/ ) ) {
279
+ return control === control_digit;
280
+
281
+ // Control must be a letter
282
+ } else if ( letter.match( /[KPQS]/ ) ) {
283
+ return control === control_letter;
284
+ }
285
+
286
+ // Can be either
287
+ return control === control_digit || control === control_letter;
211
288
 
212
- // Quick format test
213
- if ( value.length !== 9 || !cifRegEx.test( value ) ) {
214
- return false;
215
- }
289
+ }, "Please specify a valid CIF number." );
290
+
291
+ /*
292
+ * Brazillian CNH number (Carteira Nacional de Habilitacao) is the License Driver number.
293
+ * CNH numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.
294
+ */
295
+ $.validator.addMethod( "cnhBR", function( value ) {
216
296
 
217
- for ( i = 0; i < number.length; i++ ) {
218
- n = parseInt( number[ i ], 10 );
297
+ // Removing special characters from value
298
+ value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );
219
299
 
220
- // Odd positions
221
- if ( isOdd( i ) ) {
300
+ // Checking value to have 11 digits only
301
+ if ( value.length !== 11 ) {
302
+ return false;
303
+ }
222
304
 
223
- // Odd positions are multiplied first.
224
- n *= 2;
305
+ var sum = 0, dsc = 0, firstChar,
306
+ firstCN, secondCN, i, j, v;
225
307
 
226
- // If the multiplication is bigger than 10 we need to adjust
227
- odd_sum += n < 10 ? n : n - 9;
308
+ firstChar = value.charAt( 0 );
228
309
 
229
- // Even positions
230
- // Just sum them
231
- } else {
232
- even_sum += n;
233
- }
234
- }
310
+ if ( new Array( 12 ).join( firstChar ) === value ) {
311
+ return false;
312
+ }
235
313
 
236
- all_sum = even_sum + odd_sum;
237
- control_digit = ( 10 - ( all_sum ).toString().substr( -1 ) ).toString();
238
- control_digit = parseInt( control_digit, 10 ) > 9 ? "0" : control_digit;
239
- control_letter = "JABCDEFGHI".substr( control_digit, 1 ).toString();
314
+ // Step 1 - using first Check Number:
315
+ for ( i = 0, j = 9, v = 0; i < 9; ++i, --j ) {
316
+ sum += +( value.charAt( i ) * j );
317
+ }
240
318
 
241
- // Control must be a digit
242
- if ( letter.match( /[ABEH]/ ) ) {
243
- return control === control_digit;
319
+ firstCN = sum % 11;
320
+ if ( firstCN >= 10 ) {
321
+ firstCN = 0;
322
+ dsc = 2;
323
+ }
244
324
 
245
- // Control must be a letter
246
- } else if ( letter.match( /[KPQS]/ ) ) {
247
- return control === control_letter;
325
+ sum = 0;
326
+ for ( i = 0, j = 1, v = 0; i < 9; ++i, ++j ) {
327
+ sum += +( value.charAt( i ) * j );
328
+ }
248
329
 
249
- // Can be either
250
- } else {
251
- return control === control_digit || control === control_letter;
252
- }
330
+ secondCN = sum % 11;
331
+ if ( secondCN >= 10 ) {
332
+ secondCN = 0;
333
+ } else {
334
+ secondCN = secondCN - dsc;
335
+ }
253
336
 
254
- return false;
337
+ return ( String( firstCN ).concat( secondCN ) === value.substr( -2 ) );
255
338
 
256
- }, "Please specify a valid CIF number." );
339
+ }, "Please specify a valid CNH number" );
340
+
341
+ /*
342
+ * Brazillian value number (Cadastrado de Pessoas Juridica).
343
+ * value numbers have 14 digits in total: 12 numbers followed by 2 check numbers that are being used for validation.
344
+ */
345
+ $.validator.addMethod( "cnpjBR", function( value, element ) {
346
+ "use strict";
347
+
348
+ if ( this.optional( element ) ) {
349
+ return true;
350
+ }
351
+
352
+ // Removing no number
353
+ value = value.replace( /[^\d]+/g, "" );
354
+
355
+ // Checking value to have 14 digits only
356
+ if ( value.length !== 14 ) {
357
+ return false;
358
+ }
359
+
360
+ // Elimina values invalidos conhecidos
361
+ if ( value === "00000000000000" ||
362
+ value === "11111111111111" ||
363
+ value === "22222222222222" ||
364
+ value === "33333333333333" ||
365
+ value === "44444444444444" ||
366
+ value === "55555555555555" ||
367
+ value === "66666666666666" ||
368
+ value === "77777777777777" ||
369
+ value === "88888888888888" ||
370
+ value === "99999999999999" ) {
371
+ return false;
372
+ }
373
+
374
+ // Valida DVs
375
+ var tamanho = ( value.length - 2 );
376
+ var numeros = value.substring( 0, tamanho );
377
+ var digitos = value.substring( tamanho );
378
+ var soma = 0;
379
+ var pos = tamanho - 7;
380
+
381
+ for ( var i = tamanho; i >= 1; i-- ) {
382
+ soma += numeros.charAt( tamanho - i ) * pos--;
383
+ if ( pos < 2 ) {
384
+ pos = 9;
385
+ }
386
+ }
387
+
388
+ var resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
389
+
390
+ if ( resultado !== parseInt( digitos.charAt( 0 ), 10 ) ) {
391
+ return false;
392
+ }
393
+
394
+ tamanho = tamanho + 1;
395
+ numeros = value.substring( 0, tamanho );
396
+ soma = 0;
397
+ pos = tamanho - 7;
398
+
399
+ for ( var il = tamanho; il >= 1; il-- ) {
400
+ soma += numeros.charAt( tamanho - il ) * pos--;
401
+ if ( pos < 2 ) {
402
+ pos = 9;
403
+ }
404
+ }
405
+
406
+ resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
407
+
408
+ if ( resultado !== parseInt( digitos.charAt( 1 ), 10 ) ) {
409
+ return false;
410
+ }
411
+
412
+ return true;
413
+
414
+ }, "Please specify a CNPJ value number" );
257
415
 
258
416
  /*
259
417
  * Brazillian CPF number (Cadastrado de Pessoas Físicas) is the equivalent of a Brazilian tax registration number.
260
418
  * CPF numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.
261
419
  */
262
- $.validator.addMethod( "cpfBR", function( value ) {
263
-
264
- // Removing special characters from value
265
- value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );
266
-
267
- // Checking value to have 11 digits only
268
- if ( value.length !== 11 ) {
269
- return false;
270
- }
271
-
272
- var sum = 0,
273
- firstCN, secondCN, checkResult, i;
274
-
275
- firstCN = parseInt( value.substring( 9, 10 ), 10 );
276
- secondCN = parseInt( value.substring( 10, 11 ), 10 );
277
-
278
- checkResult = function( sum, cn ) {
279
- var result = ( sum * 10 ) % 11;
280
- if ( ( result === 10 ) || ( result === 11 ) ) {
281
- result = 0;
282
- }
283
- return ( result === cn );
284
- };
285
-
286
- // Checking for dump data
287
- if ( value === "" ||
288
- value === "00000000000" ||
289
- value === "11111111111" ||
290
- value === "22222222222" ||
291
- value === "33333333333" ||
292
- value === "44444444444" ||
293
- value === "55555555555" ||
294
- value === "66666666666" ||
295
- value === "77777777777" ||
296
- value === "88888888888" ||
297
- value === "99999999999"
298
- ) {
299
- return false;
300
- }
301
-
302
- // Step 1 - using first Check Number:
303
- for ( i = 1; i <= 9; i++ ) {
304
- sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 11 - i );
305
- }
306
-
307
- // If first Check Number (CN) is valid, move to Step 2 - using second Check Number:
308
- if ( checkResult( sum, firstCN ) ) {
309
- sum = 0;
310
- for ( i = 1; i <= 10; i++ ) {
311
- sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 12 - i );
312
- }
313
- return checkResult( sum, secondCN );
314
- }
315
- return false;
420
+ $.validator.addMethod( "cpfBR", function( value, element ) {
421
+ "use strict";
422
+
423
+ if ( this.optional( element ) ) {
424
+ return true;
425
+ }
426
+
427
+ // Removing special characters from value
428
+ value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );
429
+
430
+ // Checking value to have 11 digits only
431
+ if ( value.length !== 11 ) {
432
+ return false;
433
+ }
434
+
435
+ var sum = 0,
436
+ firstCN, secondCN, checkResult, i;
437
+
438
+ firstCN = parseInt( value.substring( 9, 10 ), 10 );
439
+ secondCN = parseInt( value.substring( 10, 11 ), 10 );
440
+
441
+ checkResult = function( sum, cn ) {
442
+ var result = ( sum * 10 ) % 11;
443
+ if ( ( result === 10 ) || ( result === 11 ) ) {
444
+ result = 0;
445
+ }
446
+ return ( result === cn );
447
+ };
448
+
449
+ // Checking for dump data
450
+ if ( value === "" ||
451
+ value === "00000000000" ||
452
+ value === "11111111111" ||
453
+ value === "22222222222" ||
454
+ value === "33333333333" ||
455
+ value === "44444444444" ||
456
+ value === "55555555555" ||
457
+ value === "66666666666" ||
458
+ value === "77777777777" ||
459
+ value === "88888888888" ||
460
+ value === "99999999999"
461
+ ) {
462
+ return false;
463
+ }
464
+
465
+ // Step 1 - using first Check Number:
466
+ for ( i = 1; i <= 9; i++ ) {
467
+ sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 11 - i );
468
+ }
469
+
470
+ // If first Check Number (CN) is valid, move to Step 2 - using second Check Number:
471
+ if ( checkResult( sum, firstCN ) ) {
472
+ sum = 0;
473
+ for ( i = 1; i <= 10; i++ ) {
474
+ sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 12 - i );
475
+ }
476
+ return checkResult( sum, secondCN );
477
+ }
478
+ return false;
316
479
 
317
480
  }, "Please specify a valid CPF number" );
318
481
 
319
- // http://jqueryvalidation.org/creditcard-method/
320
- // based on http://en.wikipedia.org/wiki/Luhn_algorithm
482
+ // https://jqueryvalidation.org/creditcard-method/
483
+ // based on https://en.wikipedia.org/wiki/Luhn_algorithm
321
484
  $.validator.addMethod( "creditcard", function( value, element ) {
322
- if ( this.optional( element ) ) {
323
- return "dependency-mismatch";
324
- }
325
-
326
- // Accept only spaces, digits and dashes
327
- if ( /[^0-9 \-]+/.test( value ) ) {
328
- return false;
329
- }
330
-
331
- var nCheck = 0,
332
- nDigit = 0,
333
- bEven = false,
334
- n, cDigit;
335
-
336
- value = value.replace( /\D/g, "" );
337
-
338
- // Basing min and max length on
339
- // http://developer.ean.com/general_info/Valid_Credit_Card_Types
340
- if ( value.length < 13 || value.length > 19 ) {
341
- return false;
342
- }
343
-
344
- for ( n = value.length - 1; n >= 0; n-- ) {
345
- cDigit = value.charAt( n );
346
- nDigit = parseInt( cDigit, 10 );
347
- if ( bEven ) {
348
- if ( ( nDigit *= 2 ) > 9 ) {
349
- nDigit -= 9;
350
- }
351
- }
352
-
353
- nCheck += nDigit;
354
- bEven = !bEven;
355
- }
356
-
357
- return ( nCheck % 10 ) === 0;
485
+ if ( this.optional( element ) ) {
486
+ return "dependency-mismatch";
487
+ }
488
+
489
+ // Accept only spaces, digits and dashes
490
+ if ( /[^0-9 \-]+/.test( value ) ) {
491
+ return false;
492
+ }
493
+
494
+ var nCheck = 0,
495
+ nDigit = 0,
496
+ bEven = false,
497
+ n, cDigit;
498
+
499
+ value = value.replace( /\D/g, "" );
500
+
501
+ // Basing min and max length on
502
+ // https://dev.ean.com/general-info/valid-card-types/
503
+ if ( value.length < 13 || value.length > 19 ) {
504
+ return false;
505
+ }
506
+
507
+ for ( n = value.length - 1; n >= 0; n-- ) {
508
+ cDigit = value.charAt( n );
509
+ nDigit = parseInt( cDigit, 10 );
510
+ if ( bEven ) {
511
+ if ( ( nDigit *= 2 ) > 9 ) {
512
+ nDigit -= 9;
513
+ }
514
+ }
515
+
516
+ nCheck += nDigit;
517
+ bEven = !bEven;
518
+ }
519
+
520
+ return ( nCheck % 10 ) === 0;
358
521
  }, "Please enter a valid credit card number." );
359
522
 
360
523
  /* NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
361
- * Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
524
+ * Redistributed under the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
362
525
  * Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
363
526
  */
364
527
  $.validator.addMethod( "creditcardtypes", function( value, element, param ) {
365
- if ( /[^0-9\-]+/.test( value ) ) {
366
- return false;
367
- }
368
-
369
- value = value.replace( /\D/g, "" );
370
-
371
- var validTypes = 0x0000;
372
-
373
- if ( param.mastercard ) {
374
- validTypes |= 0x0001;
375
- }
376
- if ( param.visa ) {
377
- validTypes |= 0x0002;
378
- }
379
- if ( param.amex ) {
380
- validTypes |= 0x0004;
381
- }
382
- if ( param.dinersclub ) {
383
- validTypes |= 0x0008;
384
- }
385
- if ( param.enroute ) {
386
- validTypes |= 0x0010;
387
- }
388
- if ( param.discover ) {
389
- validTypes |= 0x0020;
390
- }
391
- if ( param.jcb ) {
392
- validTypes |= 0x0040;
393
- }
394
- if ( param.unknown ) {
395
- validTypes |= 0x0080;
396
- }
397
- if ( param.all ) {
398
- validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
399
- }
400
- if ( validTypes & 0x0001 && /^(5[12345])/.test( value ) ) { // Mastercard
401
- return value.length === 16;
402
- }
403
- if ( validTypes & 0x0002 && /^(4)/.test( value ) ) { // Visa
404
- return value.length === 16;
405
- }
406
- if ( validTypes & 0x0004 && /^(3[47])/.test( value ) ) { // Amex
407
- return value.length === 15;
408
- }
409
- if ( validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test( value ) ) { // Dinersclub
410
- return value.length === 14;
411
- }
412
- if ( validTypes & 0x0010 && /^(2(014|149))/.test( value ) ) { // Enroute
413
- return value.length === 15;
414
- }
415
- if ( validTypes & 0x0020 && /^(6011)/.test( value ) ) { // Discover
416
- return value.length === 16;
417
- }
418
- if ( validTypes & 0x0040 && /^(3)/.test( value ) ) { // Jcb
419
- return value.length === 16;
420
- }
421
- if ( validTypes & 0x0040 && /^(2131|1800)/.test( value ) ) { // Jcb
422
- return value.length === 15;
423
- }
424
- if ( validTypes & 0x0080 ) { // Unknown
425
- return true;
426
- }
427
- return false;
528
+ if ( /[^0-9\-]+/.test( value ) ) {
529
+ return false;
530
+ }
531
+
532
+ value = value.replace( /\D/g, "" );
533
+
534
+ var validTypes = 0x0000;
535
+
536
+ if ( param.mastercard ) {
537
+ validTypes |= 0x0001;
538
+ }
539
+ if ( param.visa ) {
540
+ validTypes |= 0x0002;
541
+ }
542
+ if ( param.amex ) {
543
+ validTypes |= 0x0004;
544
+ }
545
+ if ( param.dinersclub ) {
546
+ validTypes |= 0x0008;
547
+ }
548
+ if ( param.enroute ) {
549
+ validTypes |= 0x0010;
550
+ }
551
+ if ( param.discover ) {
552
+ validTypes |= 0x0020;
553
+ }
554
+ if ( param.jcb ) {
555
+ validTypes |= 0x0040;
556
+ }
557
+ if ( param.unknown ) {
558
+ validTypes |= 0x0080;
559
+ }
560
+ if ( param.all ) {
561
+ validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
562
+ }
563
+ if ( validTypes & 0x0001 && ( /^(5[12345])/.test( value ) || /^(2[234567])/.test( value ) ) ) { // Mastercard
564
+ return value.length === 16;
565
+ }
566
+ if ( validTypes & 0x0002 && /^(4)/.test( value ) ) { // Visa
567
+ return value.length === 16;
568
+ }
569
+ if ( validTypes & 0x0004 && /^(3[47])/.test( value ) ) { // Amex
570
+ return value.length === 15;
571
+ }
572
+ if ( validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test( value ) ) { // Dinersclub
573
+ return value.length === 14;
574
+ }
575
+ if ( validTypes & 0x0010 && /^(2(014|149))/.test( value ) ) { // Enroute
576
+ return value.length === 15;
577
+ }
578
+ if ( validTypes & 0x0020 && /^(6011)/.test( value ) ) { // Discover
579
+ return value.length === 16;
580
+ }
581
+ if ( validTypes & 0x0040 && /^(3)/.test( value ) ) { // Jcb
582
+ return value.length === 16;
583
+ }
584
+ if ( validTypes & 0x0040 && /^(2131|1800)/.test( value ) ) { // Jcb
585
+ return value.length === 15;
586
+ }
587
+ if ( validTypes & 0x0080 ) { // Unknown
588
+ return true;
589
+ }
590
+ return false;
428
591
  }, "Please enter a valid credit card number." );
429
592
 
430
593
  /**
@@ -470,7 +633,7 @@ $.validator.addMethod( "currency", function( value, element, param ) {
470
633
  }, "Please specify a valid currency" );
471
634
 
472
635
  $.validator.addMethod( "dateFA", function( value, element ) {
473
- return this.optional( element ) || /^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test( value );
636
+ return this.optional( element ) || /^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test( value );
474
637
  }, $.validator.messages.date );
475
638
 
476
639
  /**
@@ -493,43 +656,67 @@ $.validator.addMethod( "dateFA", function( value, element ) {
493
656
  * @cat Plugins/Validate/Methods
494
657
  */
495
658
  $.validator.addMethod( "dateITA", function( value, element ) {
496
- var check = false,
497
- re = /^\d{1,2}\/\d{1,2}\/\d{4}$/,
498
- adata, gg, mm, aaaa, xdata;
499
- if ( re.test( value ) ) {
500
- adata = value.split( "/" );
501
- gg = parseInt( adata[ 0 ], 10 );
502
- mm = parseInt( adata[ 1 ], 10 );
503
- aaaa = parseInt( adata[ 2 ], 10 );
504
- xdata = new Date( Date.UTC( aaaa, mm - 1, gg, 12, 0, 0, 0 ) );
505
- if ( ( xdata.getUTCFullYear() === aaaa ) && ( xdata.getUTCMonth() === mm - 1 ) && ( xdata.getUTCDate() === gg ) ) {
506
- check = true;
507
- } else {
508
- check = false;
509
- }
510
- } else {
511
- check = false;
512
- }
513
- return this.optional( element ) || check;
659
+ var check = false,
660
+ re = /^\d{1,2}\/\d{1,2}\/\d{4}$/,
661
+ adata, gg, mm, aaaa, xdata;
662
+ if ( re.test( value ) ) {
663
+ adata = value.split( "/" );
664
+ gg = parseInt( adata[ 0 ], 10 );
665
+ mm = parseInt( adata[ 1 ], 10 );
666
+ aaaa = parseInt( adata[ 2 ], 10 );
667
+ xdata = new Date( Date.UTC( aaaa, mm - 1, gg, 12, 0, 0, 0 ) );
668
+ if ( ( xdata.getUTCFullYear() === aaaa ) && ( xdata.getUTCMonth() === mm - 1 ) && ( xdata.getUTCDate() === gg ) ) {
669
+ check = true;
670
+ } else {
671
+ check = false;
672
+ }
673
+ } else {
674
+ check = false;
675
+ }
676
+ return this.optional( element ) || check;
514
677
  }, $.validator.messages.date );
515
678
 
516
679
  $.validator.addMethod( "dateNL", function( value, element ) {
517
- return this.optional( element ) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test( value );
680
+ return this.optional( element ) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test( value );
518
681
  }, $.validator.messages.date );
519
682
 
520
683
  // Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept
521
684
  $.validator.addMethod( "extension", function( value, element, param ) {
522
- param = typeof param === "string" ? param.replace( /,/g, "|" ) : "png|jpe?g|gif";
523
- return this.optional( element ) || value.match( new RegExp( "\\.(" + param + ")$", "i" ) );
685
+ param = typeof param === "string" ? param.replace( /,/g, "|" ) : "png|jpe?g|gif";
686
+ return this.optional( element ) || value.match( new RegExp( "\\.(" + param + ")$", "i" ) );
524
687
  }, $.validator.format( "Please enter a value with a valid extension." ) );
525
688
 
526
689
  /**
527
690
  * Dutch giro account numbers (not bank numbers) have max 7 digits
528
691
  */
529
692
  $.validator.addMethod( "giroaccountNL", function( value, element ) {
530
- return this.optional( element ) || /^[0-9]{1,7}$/.test( value );
693
+ return this.optional( element ) || /^[0-9]{1,7}$/.test( value );
531
694
  }, "Please specify a valid giro account number" );
532
695
 
696
+ $.validator.addMethod( "greaterThan", function( value, element, param ) {
697
+ var target = $( param );
698
+
699
+ if ( this.settings.onfocusout && target.not( ".validate-greaterThan-blur" ).length ) {
700
+ target.addClass( "validate-greaterThan-blur" ).on( "blur.validate-greaterThan", function() {
701
+ $( element ).valid();
702
+ } );
703
+ }
704
+
705
+ return value > target.val();
706
+ }, "Please enter a greater value." );
707
+
708
+ $.validator.addMethod( "greaterThanEqual", function( value, element, param ) {
709
+ var target = $( param );
710
+
711
+ if ( this.settings.onfocusout && target.not( ".validate-greaterThanEqual-blur" ).length ) {
712
+ target.addClass( "validate-greaterThanEqual-blur" ).on( "blur.validate-greaterThanEqual", function() {
713
+ $( element ).valid();
714
+ } );
715
+ }
716
+
717
+ return value >= target.val();
718
+ }, "Please enter a greater value." );
719
+
533
720
  /**
534
721
  * IBAN is the international bank account number.
535
722
  * It has a country - specific format, that is checked here too
@@ -538,157 +725,243 @@ $.validator.addMethod( "giroaccountNL", function( value, element ) {
538
725
  */
539
726
  $.validator.addMethod( "iban", function( value, element ) {
540
727
 
541
- // Some quick simple tests to prevent needless work
542
- if ( this.optional( element ) ) {
543
- return true;
544
- }
545
-
546
- // Remove spaces and to upper case
547
- var iban = value.replace( / /g, "" ).toUpperCase(),
548
- ibancheckdigits = "",
549
- leadingZeroes = true,
550
- cRest = "",
551
- cOperator = "",
552
- countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;
553
-
554
- // Check for IBAN code length.
555
- // It contains:
556
- // country code ISO 3166-1 - two letters,
557
- // two check digits,
558
- // Basic Bank Account Number (BBAN) - up to 30 chars
559
- var minimalIBANlength = 5;
560
- if ( iban.length < minimalIBANlength ) {
561
- return false;
562
- }
563
-
564
- // Check the country code and find the country specific format
565
- countrycode = iban.substring( 0, 2 );
566
- bbancountrypatterns = {
567
- "AL": "\\d{8}[\\dA-Z]{16}",
568
- "AD": "\\d{8}[\\dA-Z]{12}",
569
- "AT": "\\d{16}",
570
- "AZ": "[\\dA-Z]{4}\\d{20}",
571
- "BE": "\\d{12}",
572
- "BH": "[A-Z]{4}[\\dA-Z]{14}",
573
- "BA": "\\d{16}",
574
- "BR": "\\d{23}[A-Z][\\dA-Z]",
575
- "BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
576
- "CR": "\\d{17}",
577
- "HR": "\\d{17}",
578
- "CY": "\\d{8}[\\dA-Z]{16}",
579
- "CZ": "\\d{20}",
580
- "DK": "\\d{14}",
581
- "DO": "[A-Z]{4}\\d{20}",
582
- "EE": "\\d{16}",
583
- "FO": "\\d{14}",
584
- "FI": "\\d{14}",
585
- "FR": "\\d{10}[\\dA-Z]{11}\\d{2}",
586
- "GE": "[\\dA-Z]{2}\\d{16}",
587
- "DE": "\\d{18}",
588
- "GI": "[A-Z]{4}[\\dA-Z]{15}",
589
- "GR": "\\d{7}[\\dA-Z]{16}",
590
- "GL": "\\d{14}",
591
- "GT": "[\\dA-Z]{4}[\\dA-Z]{20}",
592
- "HU": "\\d{24}",
593
- "IS": "\\d{22}",
594
- "IE": "[\\dA-Z]{4}\\d{14}",
595
- "IL": "\\d{19}",
596
- "IT": "[A-Z]\\d{10}[\\dA-Z]{12}",
597
- "KZ": "\\d{3}[\\dA-Z]{13}",
598
- "KW": "[A-Z]{4}[\\dA-Z]{22}",
599
- "LV": "[A-Z]{4}[\\dA-Z]{13}",
600
- "LB": "\\d{4}[\\dA-Z]{20}",
601
- "LI": "\\d{5}[\\dA-Z]{12}",
602
- "LT": "\\d{16}",
603
- "LU": "\\d{3}[\\dA-Z]{13}",
604
- "MK": "\\d{3}[\\dA-Z]{10}\\d{2}",
605
- "MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
606
- "MR": "\\d{23}",
607
- "MU": "[A-Z]{4}\\d{19}[A-Z]{3}",
608
- "MC": "\\d{10}[\\dA-Z]{11}\\d{2}",
609
- "MD": "[\\dA-Z]{2}\\d{18}",
610
- "ME": "\\d{18}",
611
- "NL": "[A-Z]{4}\\d{10}",
612
- "NO": "\\d{11}",
613
- "PK": "[\\dA-Z]{4}\\d{16}",
614
- "PS": "[\\dA-Z]{4}\\d{21}",
615
- "PL": "\\d{24}",
616
- "PT": "\\d{21}",
617
- "RO": "[A-Z]{4}[\\dA-Z]{16}",
618
- "SM": "[A-Z]\\d{10}[\\dA-Z]{12}",
619
- "SA": "\\d{2}[\\dA-Z]{18}",
620
- "RS": "\\d{18}",
621
- "SK": "\\d{20}",
622
- "SI": "\\d{15}",
623
- "ES": "\\d{20}",
624
- "SE": "\\d{20}",
625
- "CH": "\\d{5}[\\dA-Z]{12}",
626
- "TN": "\\d{20}",
627
- "TR": "\\d{5}[\\dA-Z]{17}",
628
- "AE": "\\d{3}\\d{16}",
629
- "GB": "[A-Z]{4}\\d{14}",
630
- "VG": "[\\dA-Z]{4}\\d{16}"
631
- };
632
-
633
- bbanpattern = bbancountrypatterns[ countrycode ];
634
-
635
- // As new countries will start using IBAN in the
636
- // future, we only check if the countrycode is known.
637
- // This prevents false negatives, while almost all
638
- // false positives introduced by this, will be caught
639
- // by the checksum validation below anyway.
640
- // Strict checking should return FALSE for unknown
641
- // countries.
642
- if ( typeof bbanpattern !== "undefined" ) {
643
- ibanregexp = new RegExp( "^[A-Z]{2}\\d{2}" + bbanpattern + "$", "" );
644
- if ( !( ibanregexp.test( iban ) ) ) {
645
- return false; // Invalid country specific format
646
- }
647
- }
648
-
649
- // Now check the checksum, first convert to digits
650
- ibancheck = iban.substring( 4, iban.length ) + iban.substring( 0, 4 );
651
- for ( i = 0; i < ibancheck.length; i++ ) {
652
- charAt = ibancheck.charAt( i );
653
- if ( charAt !== "0" ) {
654
- leadingZeroes = false;
655
- }
656
- if ( !leadingZeroes ) {
657
- ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf( charAt );
658
- }
659
- }
660
-
661
- // Calculate the result of: ibancheckdigits % 97
662
- for ( p = 0; p < ibancheckdigits.length; p++ ) {
663
- cChar = ibancheckdigits.charAt( p );
664
- cOperator = "" + cRest + "" + cChar;
665
- cRest = cOperator % 97;
666
- }
667
- return cRest === 1;
728
+ // Some quick simple tests to prevent needless work
729
+ if ( this.optional( element ) ) {
730
+ return true;
731
+ }
732
+
733
+ // Remove spaces and to upper case
734
+ var iban = value.replace( / /g, "" ).toUpperCase(),
735
+ ibancheckdigits = "",
736
+ leadingZeroes = true,
737
+ cRest = "",
738
+ cOperator = "",
739
+ countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;
740
+
741
+ // Check for IBAN code length.
742
+ // It contains:
743
+ // country code ISO 3166-1 - two letters,
744
+ // two check digits,
745
+ // Basic Bank Account Number (BBAN) - up to 30 chars
746
+ var minimalIBANlength = 5;
747
+ if ( iban.length < minimalIBANlength ) {
748
+ return false;
749
+ }
750
+
751
+ // Check the country code and find the country specific format
752
+ countrycode = iban.substring( 0, 2 );
753
+ bbancountrypatterns = {
754
+ "AL": "\\d{8}[\\dA-Z]{16}",
755
+ "AD": "\\d{8}[\\dA-Z]{12}",
756
+ "AT": "\\d{16}",
757
+ "AZ": "[\\dA-Z]{4}\\d{20}",
758
+ "BE": "\\d{12}",
759
+ "BH": "[A-Z]{4}[\\dA-Z]{14}",
760
+ "BA": "\\d{16}",
761
+ "BR": "\\d{23}[A-Z][\\dA-Z]",
762
+ "BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
763
+ "CR": "\\d{17}",
764
+ "HR": "\\d{17}",
765
+ "CY": "\\d{8}[\\dA-Z]{16}",
766
+ "CZ": "\\d{20}",
767
+ "DK": "\\d{14}",
768
+ "DO": "[A-Z]{4}\\d{20}",
769
+ "EE": "\\d{16}",
770
+ "FO": "\\d{14}",
771
+ "FI": "\\d{14}",
772
+ "FR": "\\d{10}[\\dA-Z]{11}\\d{2}",
773
+ "GE": "[\\dA-Z]{2}\\d{16}",
774
+ "DE": "\\d{18}",
775
+ "GI": "[A-Z]{4}[\\dA-Z]{15}",
776
+ "GR": "\\d{7}[\\dA-Z]{16}",
777
+ "GL": "\\d{14}",
778
+ "GT": "[\\dA-Z]{4}[\\dA-Z]{20}",
779
+ "HU": "\\d{24}",
780
+ "IS": "\\d{22}",
781
+ "IE": "[\\dA-Z]{4}\\d{14}",
782
+ "IL": "\\d{19}",
783
+ "IT": "[A-Z]\\d{10}[\\dA-Z]{12}",
784
+ "KZ": "\\d{3}[\\dA-Z]{13}",
785
+ "KW": "[A-Z]{4}[\\dA-Z]{22}",
786
+ "LV": "[A-Z]{4}[\\dA-Z]{13}",
787
+ "LB": "\\d{4}[\\dA-Z]{20}",
788
+ "LI": "\\d{5}[\\dA-Z]{12}",
789
+ "LT": "\\d{16}",
790
+ "LU": "\\d{3}[\\dA-Z]{13}",
791
+ "MK": "\\d{3}[\\dA-Z]{10}\\d{2}",
792
+ "MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
793
+ "MR": "\\d{23}",
794
+ "MU": "[A-Z]{4}\\d{19}[A-Z]{3}",
795
+ "MC": "\\d{10}[\\dA-Z]{11}\\d{2}",
796
+ "MD": "[\\dA-Z]{2}\\d{18}",
797
+ "ME": "\\d{18}",
798
+ "NL": "[A-Z]{4}\\d{10}",
799
+ "NO": "\\d{11}",
800
+ "PK": "[\\dA-Z]{4}\\d{16}",
801
+ "PS": "[\\dA-Z]{4}\\d{21}",
802
+ "PL": "\\d{24}",
803
+ "PT": "\\d{21}",
804
+ "RO": "[A-Z]{4}[\\dA-Z]{16}",
805
+ "SM": "[A-Z]\\d{10}[\\dA-Z]{12}",
806
+ "SA": "\\d{2}[\\dA-Z]{18}",
807
+ "RS": "\\d{18}",
808
+ "SK": "\\d{20}",
809
+ "SI": "\\d{15}",
810
+ "ES": "\\d{20}",
811
+ "SE": "\\d{20}",
812
+ "CH": "\\d{5}[\\dA-Z]{12}",
813
+ "TN": "\\d{20}",
814
+ "TR": "\\d{5}[\\dA-Z]{17}",
815
+ "AE": "\\d{3}\\d{16}",
816
+ "GB": "[A-Z]{4}\\d{14}",
817
+ "VG": "[\\dA-Z]{4}\\d{16}"
818
+ };
819
+
820
+ bbanpattern = bbancountrypatterns[ countrycode ];
821
+
822
+ // As new countries will start using IBAN in the
823
+ // future, we only check if the countrycode is known.
824
+ // This prevents false negatives, while almost all
825
+ // false positives introduced by this, will be caught
826
+ // by the checksum validation below anyway.
827
+ // Strict checking should return FALSE for unknown
828
+ // countries.
829
+ if ( typeof bbanpattern !== "undefined" ) {
830
+ ibanregexp = new RegExp( "^[A-Z]{2}\\d{2}" + bbanpattern + "$", "" );
831
+ if ( !( ibanregexp.test( iban ) ) ) {
832
+ return false; // Invalid country specific format
833
+ }
834
+ }
835
+
836
+ // Now check the checksum, first convert to digits
837
+ ibancheck = iban.substring( 4, iban.length ) + iban.substring( 0, 4 );
838
+ for ( i = 0; i < ibancheck.length; i++ ) {
839
+ charAt = ibancheck.charAt( i );
840
+ if ( charAt !== "0" ) {
841
+ leadingZeroes = false;
842
+ }
843
+ if ( !leadingZeroes ) {
844
+ ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf( charAt );
845
+ }
846
+ }
847
+
848
+ // Calculate the result of: ibancheckdigits % 97
849
+ for ( p = 0; p < ibancheckdigits.length; p++ ) {
850
+ cChar = ibancheckdigits.charAt( p );
851
+ cOperator = "" + cRest + "" + cChar;
852
+ cRest = cOperator % 97;
853
+ }
854
+ return cRest === 1;
668
855
  }, "Please specify a valid IBAN" );
669
856
 
670
857
  $.validator.addMethod( "integer", function( value, element ) {
671
- return this.optional( element ) || /^-?\d+$/.test( value );
858
+ return this.optional( element ) || /^-?\d+$/.test( value );
672
859
  }, "A positive or negative non-decimal number please" );
673
860
 
674
861
  $.validator.addMethod( "ipv4", function( value, element ) {
675
- 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 );
862
+ 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 );
676
863
  }, "Please enter a valid IP v4 address." );
677
864
 
678
865
  $.validator.addMethod( "ipv6", function( value, element ) {
679
- 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 );
866
+ 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 );
680
867
  }, "Please enter a valid IP v6 address." );
681
868
 
869
+ $.validator.addMethod( "lessThan", function( value, element, param ) {
870
+ var target = $( param );
871
+
872
+ if ( this.settings.onfocusout && target.not( ".validate-lessThan-blur" ).length ) {
873
+ target.addClass( "validate-lessThan-blur" ).on( "blur.validate-lessThan", function() {
874
+ $( element ).valid();
875
+ } );
876
+ }
877
+
878
+ return value < target.val();
879
+ }, "Please enter a lesser value." );
880
+
881
+ $.validator.addMethod( "lessThanEqual", function( value, element, param ) {
882
+ var target = $( param );
883
+
884
+ if ( this.settings.onfocusout && target.not( ".validate-lessThanEqual-blur" ).length ) {
885
+ target.addClass( "validate-lessThanEqual-blur" ).on( "blur.validate-lessThanEqual", function() {
886
+ $( element ).valid();
887
+ } );
888
+ }
889
+
890
+ return value <= target.val();
891
+ }, "Please enter a lesser value." );
892
+
682
893
  $.validator.addMethod( "lettersonly", function( value, element ) {
683
- return this.optional( element ) || /^[a-z]+$/i.test( value );
894
+ return this.optional( element ) || /^[a-z]+$/i.test( value );
684
895
  }, "Letters only please" );
685
896
 
686
897
  $.validator.addMethod( "letterswithbasicpunc", function( value, element ) {
687
- return this.optional( element ) || /^[a-z\-.,()'"\s]+$/i.test( value );
898
+ return this.optional( element ) || /^[a-z\-.,()'"\s]+$/i.test( value );
688
899
  }, "Letters or punctuation only please" );
689
900
 
901
+ // Limit the number of files in a FileList.
902
+ $.validator.addMethod( "maxfiles", function( value, element, param ) {
903
+ if ( this.optional( element ) ) {
904
+ return true;
905
+ }
906
+
907
+ if ( $( element ).attr( "type" ) === "file" ) {
908
+ if ( element.files && element.files.length > param ) {
909
+ return false;
910
+ }
911
+ }
912
+
913
+ return true;
914
+ }, $.validator.format( "Please select no more than {0} files." ) );
915
+
916
+ // Limit the size of each individual file in a FileList.
917
+ $.validator.addMethod( "maxsize", function( value, element, param ) {
918
+ if ( this.optional( element ) ) {
919
+ return true;
920
+ }
921
+
922
+ if ( $( element ).attr( "type" ) === "file" ) {
923
+ if ( element.files && element.files.length ) {
924
+ for ( var i = 0; i < element.files.length; i++ ) {
925
+ if ( element.files[ i ].size > param ) {
926
+ return false;
927
+ }
928
+ }
929
+ }
930
+ }
931
+
932
+ return true;
933
+ }, $.validator.format( "File size must not exceed {0} bytes each." ) );
934
+
935
+ // Limit the size of all files in a FileList.
936
+ $.validator.addMethod( "maxsizetotal", function( value, element, param ) {
937
+ if ( this.optional( element ) ) {
938
+ return true;
939
+ }
940
+
941
+ if ( $( element ).attr( "type" ) === "file" ) {
942
+ if ( element.files && element.files.length ) {
943
+ var totalSize = 0;
944
+
945
+ for ( var i = 0; i < element.files.length; i++ ) {
946
+ totalSize += element.files[ i ].size;
947
+ if ( totalSize > param ) {
948
+ return false;
949
+ }
950
+ }
951
+ }
952
+ }
953
+
954
+ return true;
955
+ }, $.validator.format( "Total size of all files must not exceed {0} bytes." ) );
956
+
957
+
690
958
  $.validator.addMethod( "mobileNL", function( value, element ) {
691
- return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test( value );
959
+ return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test( value );
960
+ }, "Please specify a valid mobile number" );
961
+
962
+ $.validator.addMethod( "mobileRU", function( phone_number, element ) {
963
+ var ruPhone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
964
+ return this.optional( element ) || ruPhone_number.length > 9 && /^((\+7|7|8)+([0-9]){10})$/.test( ruPhone_number );
692
965
  }, "Please specify a valid mobile number" );
693
966
 
694
967
  /* For UK phone functions, do the following server side processing:
@@ -700,11 +973,15 @@ $.validator.addMethod( "mobileNL", function( value, element ) {
700
973
  * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
701
974
  */
702
975
  $.validator.addMethod( "mobileUK", function( phone_number, element ) {
703
- phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
704
- return this.optional( element ) || phone_number.length > 9 &&
705
- phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/ );
976
+ phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
977
+ return this.optional( element ) || phone_number.length > 9 &&
978
+ phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/ );
706
979
  }, "Please specify a valid mobile number" );
707
980
 
981
+ $.validator.addMethod( "netmask", function( value, element ) {
982
+ return this.optional( element ) || /^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)/i.test( value );
983
+ }, "Please enter a valid netmask." );
984
+
708
985
  /*
709
986
  * The NIE (Número de Identificación de Extranjero) is a Spanish tax identification number assigned by the Spanish
710
987
  * authorities to any foreigner.
@@ -713,67 +990,156 @@ $.validator.addMethod( "mobileUK", function( phone_number, element ) {
713
990
  * identification number. The CIF number (Certificado de Identificación Fiscal) is equivalent to the NIF, but applies to
714
991
  * companies rather than individuals. The NIE consists of an 'X' or 'Y' followed by 7 or 8 digits then another letter.
715
992
  */
716
- $.validator.addMethod( "nieES", function( value ) {
717
- "use strict";
993
+ $.validator.addMethod( "nieES", function( value, element ) {
994
+ "use strict";
718
995
 
719
- var nieRegEx = new RegExp( /^[MXYZ]{1}[0-9]{7,8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/gi );
720
- var validChars = "TRWAGMYFPDXBNJZSQVHLCKET",
721
- letter = value.substr( value.length - 1 ).toUpperCase(),
722
- number;
996
+ if ( this.optional( element ) ) {
997
+ return true;
998
+ }
723
999
 
724
- value = value.toString().toUpperCase();
1000
+ var nieRegEx = new RegExp( /^[MXYZ]{1}[0-9]{7,8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/gi );
1001
+ var validChars = "TRWAGMYFPDXBNJZSQVHLCKET",
1002
+ letter = value.substr( value.length - 1 ).toUpperCase(),
1003
+ number;
725
1004
 
726
- // Quick format test
727
- if ( value.length > 10 || value.length < 9 || !nieRegEx.test( value ) ) {
728
- return false;
729
- }
1005
+ value = value.toString().toUpperCase();
1006
+
1007
+ // Quick format test
1008
+ if ( value.length > 10 || value.length < 9 || !nieRegEx.test( value ) ) {
1009
+ return false;
1010
+ }
730
1011
 
731
- // X means same number
732
- // Y means number + 10000000
733
- // Z means number + 20000000
734
- value = value.replace( /^[X]/, "0" )
735
- .replace( /^[Y]/, "1" )
736
- .replace( /^[Z]/, "2" );
1012
+ // X means same number
1013
+ // Y means number + 10000000
1014
+ // Z means number + 20000000
1015
+ value = value.replace( /^[X]/, "0" )
1016
+ .replace( /^[Y]/, "1" )
1017
+ .replace( /^[Z]/, "2" );
737
1018
 
738
- number = value.length === 9 ? value.substr( 0, 8 ) : value.substr( 0, 9 );
1019
+ number = value.length === 9 ? value.substr( 0, 8 ) : value.substr( 0, 9 );
739
1020
 
740
- return validChars.charAt( parseInt( number, 10 ) % 23 ) === letter;
1021
+ return validChars.charAt( parseInt( number, 10 ) % 23 ) === letter;
741
1022
 
742
1023
  }, "Please specify a valid NIE number." );
743
1024
 
744
1025
  /*
745
1026
  * The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
746
1027
  */
747
- $.validator.addMethod( "nifES", function( value ) {
748
- "use strict";
1028
+ $.validator.addMethod( "nifES", function( value, element ) {
1029
+ "use strict";
749
1030
 
750
- value = value.toUpperCase();
1031
+ if ( this.optional( element ) ) {
1032
+ return true;
1033
+ }
751
1034
 
752
- // Basic format test
753
- if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {
754
- return false;
755
- }
1035
+ value = value.toUpperCase();
756
1036
 
757
- // Test NIF
758
- if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {
759
- return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );
760
- }
1037
+ // Basic format test
1038
+ if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {
1039
+ return false;
1040
+ }
761
1041
 
762
- // Test specials NIF (starts with K, L or M)
763
- if ( /^[KLM]{1}/.test( value ) ) {
764
- return ( value[ 8 ] === String.fromCharCode( 64 ) );
765
- }
1042
+ // Test NIF
1043
+ if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {
1044
+ return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );
1045
+ }
766
1046
 
767
- return false;
1047
+ // Test specials NIF (starts with K, L or M)
1048
+ if ( /^[KLM]{1}/.test( value ) ) {
1049
+ return ( value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 1 ) % 23 ) );
1050
+ }
1051
+
1052
+ return false;
768
1053
 
769
1054
  }, "Please specify a valid NIF number." );
770
1055
 
1056
+ /*
1057
+ * Numer identyfikacji podatkowej ( NIP ) is the way tax identification used in Poland for companies
1058
+ */
1059
+ $.validator.addMethod( "nipPL", function( value ) {
1060
+ "use strict";
1061
+
1062
+ value = value.replace( /[^0-9]/g, "" );
1063
+
1064
+ if ( value.length !== 10 ) {
1065
+ return false;
1066
+ }
1067
+
1068
+ var arrSteps = [ 6, 5, 7, 2, 3, 4, 5, 6, 7 ];
1069
+ var intSum = 0;
1070
+ for ( var i = 0; i < 9; i++ ) {
1071
+ intSum += arrSteps[ i ] * value[ i ];
1072
+ }
1073
+ var int2 = intSum % 11;
1074
+ var intControlNr = ( int2 === 10 ) ? 0 : int2;
1075
+
1076
+ return ( intControlNr === parseInt( value[ 9 ], 10 ) );
1077
+ }, "Please specify a valid NIP number." );
1078
+
1079
+ /**
1080
+ * Created for project jquery-validation.
1081
+ * @Description Brazillian PIS or NIS number (Número de Identificação Social Pis ou Pasep) is the equivalent of a
1082
+ * Brazilian tax registration number NIS of PIS numbers have 11 digits in total: 10 numbers followed by 1 check numbers
1083
+ * that are being used for validation.
1084
+ * @copyright (c) 21/08/2018 13:14, Cleiton da Silva Mendonça
1085
+ * @author Cleiton da Silva Mendonça <cleiton.mendonca@gmail.com>
1086
+ * @link http://gitlab.com/csmendonca Gitlab of Cleiton da Silva Mendonça
1087
+ * @link http://github.com/csmendonca Github of Cleiton da Silva Mendonça
1088
+ */
1089
+ $.validator.addMethod( "nisBR", function( value ) {
1090
+ var number;
1091
+ var cn;
1092
+ var sum = 0;
1093
+ var dv;
1094
+ var count;
1095
+ var multiplier;
1096
+
1097
+ // Removing special characters from value
1098
+ value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );
1099
+
1100
+ // Checking value to have 11 digits only
1101
+ if ( value.length !== 11 ) {
1102
+ return false;
1103
+ }
1104
+
1105
+ //Get check number of value
1106
+ cn = parseInt( value.substring( 10, 11 ), 10 );
1107
+
1108
+ //Get number with 10 digits of the value
1109
+ number = parseInt( value.substring( 0, 10 ), 10 );
1110
+
1111
+ for ( count = 2; count < 12; count++ ) {
1112
+ multiplier = count;
1113
+ if ( count === 10 ) {
1114
+ multiplier = 2;
1115
+ }
1116
+ if ( count === 11 ) {
1117
+ multiplier = 3;
1118
+ }
1119
+ sum += ( ( number % 10 ) * multiplier );
1120
+ number = parseInt( number / 10, 10 );
1121
+ }
1122
+ dv = ( sum % 11 );
1123
+
1124
+ if ( dv > 1 ) {
1125
+ dv = ( 11 - dv );
1126
+ } else {
1127
+ dv = 0;
1128
+ }
1129
+
1130
+ if ( cn === dv ) {
1131
+ return true;
1132
+ } else {
1133
+ return false;
1134
+ }
1135
+ }, "Please specify a valid NIS/PIS number" );
1136
+
771
1137
  $.validator.addMethod( "notEqualTo", function( value, element, param ) {
772
- return this.optional( element ) || !$.validator.methods.equalTo.call( this, value, element, param );
1138
+ return this.optional( element ) || !$.validator.methods.equalTo.call( this, value, element, param );
773
1139
  }, "Please enter a different value, values must not be the same." );
774
1140
 
775
1141
  $.validator.addMethod( "nowhitespace", function( value, element ) {
776
- return this.optional( element ) || /^\S+$/i.test( value );
1142
+ return this.optional( element ) || /^\S+$/i.test( value );
777
1143
  }, "No white space please" );
778
1144
 
779
1145
  /**
@@ -790,22 +1156,46 @@ $.validator.addMethod( "nowhitespace", function( value, element ) {
790
1156
  * @cat Plugins/Validate/Methods
791
1157
  */
792
1158
  $.validator.addMethod( "pattern", function( value, element, param ) {
793
- if ( this.optional( element ) ) {
794
- return true;
795
- }
796
- if ( typeof param === "string" ) {
797
- param = new RegExp( "^(?:" + param + ")$" );
798
- }
799
- return param.test( value );
1159
+ if ( this.optional( element ) ) {
1160
+ return true;
1161
+ }
1162
+ if ( typeof param === "string" ) {
1163
+ param = new RegExp( "^(?:" + param + ")$" );
1164
+ }
1165
+ return param.test( value );
800
1166
  }, "Invalid format." );
801
1167
 
802
1168
  /**
803
1169
  * Dutch phone numbers have 10 digits (or 11 and start with +31).
804
1170
  */
805
1171
  $.validator.addMethod( "phoneNL", function( value, element ) {
806
- return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test( value );
1172
+ return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test( value );
807
1173
  }, "Please specify a valid phone number." );
808
1174
 
1175
+ /**
1176
+ * Polish telephone numbers have 9 digits.
1177
+ *
1178
+ * Mobile phone numbers starts with following digits:
1179
+ * 45, 50, 51, 53, 57, 60, 66, 69, 72, 73, 78, 79, 88.
1180
+ *
1181
+ * Fixed-line numbers starts with area codes:
1182
+ * 12, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 29, 32, 33,
1183
+ * 34, 41, 42, 43, 44, 46, 48, 52, 54, 55, 56, 58, 59, 61,
1184
+ * 62, 63, 65, 67, 68, 71, 74, 75, 76, 77, 81, 82, 83, 84,
1185
+ * 85, 86, 87, 89, 91, 94, 95.
1186
+ *
1187
+ * Ministry of National Defence numbers and VoIP numbers starts with 26 and 39.
1188
+ *
1189
+ * Excludes intelligent networks (premium rate, shared cost, free phone numbers).
1190
+ *
1191
+ * Poland National Numbering Plan http://www.itu.int/oth/T02020000A8/en
1192
+ */
1193
+ $.validator.addMethod( "phonePL", function( phone_number, element ) {
1194
+ phone_number = phone_number.replace( /\s+/g, "" );
1195
+ var regexp = /^(?:(?:(?:\+|00)?48)|(?:\(\+?48\)))?(?:1[2-8]|2[2-69]|3[2-49]|4[1-68]|5[0-9]|6[0-35-9]|[7-8][1-9]|9[145])\d{7}$/;
1196
+ return this.optional( element ) || regexp.test( phone_number );
1197
+ }, "Please specify a valid phone number" );
1198
+
809
1199
  /* For UK phone functions, do the following server side processing:
810
1200
  * Compare original input with this RegEx pattern:
811
1201
  * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
@@ -817,9 +1207,9 @@ $.validator.addMethod( "phoneNL", function( value, element ) {
817
1207
 
818
1208
  // Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
819
1209
  $.validator.addMethod( "phonesUK", function( phone_number, element ) {
820
- phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
821
- return this.optional( element ) || phone_number.length > 9 &&
822
- phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/ );
1210
+ phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
1211
+ return this.optional( element ) || phone_number.length > 9 &&
1212
+ phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/ );
823
1213
  }, "Please specify a valid uk phone number" );
824
1214
 
825
1215
  /* For UK phone functions, do the following server side processing:
@@ -831,9 +1221,9 @@ $.validator.addMethod( "phonesUK", function( phone_number, element ) {
831
1221
  * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
832
1222
  */
833
1223
  $.validator.addMethod( "phoneUK", function( phone_number, element ) {
834
- phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
835
- return this.optional( element ) || phone_number.length > 9 &&
836
- phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/ );
1224
+ phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
1225
+ return this.optional( element ) || phone_number.length > 9 &&
1226
+ phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/ );
837
1227
  }, "Please specify a valid phone number" );
838
1228
 
839
1229
  /**
@@ -853,9 +1243,9 @@ $.validator.addMethod( "phoneUK", function( phone_number, element ) {
853
1243
  * 212 123 4567
854
1244
  */
855
1245
  $.validator.addMethod( "phoneUS", function( phone_number, element ) {
856
- phone_number = phone_number.replace( /\s+/g, "" );
857
- return this.optional( element ) || phone_number.length > 9 &&
858
- phone_number.match( /^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/ );
1246
+ phone_number = phone_number.replace( /\s+/g, "" );
1247
+ return this.optional( element ) || phone_number.length > 9 &&
1248
+ phone_number.match( /^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]\d{2}-?\d{4}$/ );
859
1249
  }, "Please specify a valid phone number" );
860
1250
 
861
1251
  /*
@@ -867,7 +1257,7 @@ $.validator.addMethod( "phoneUS", function( phone_number, element ) {
867
1257
  * 99999999
868
1258
  */
869
1259
  $.validator.addMethod( "postalcodeBR", function( cep_value, element ) {
870
- return this.optional( element ) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );
1260
+ return this.optional( element ) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );
871
1261
  }, "Informe um CEP válido." );
872
1262
 
873
1263
  /**
@@ -884,21 +1274,21 @@ $.validator.addMethod( "postalcodeBR", function( cep_value, element ) {
884
1274
  * @cat Plugins/Validate/Methods
885
1275
  */
886
1276
  $.validator.addMethod( "postalCodeCA", function( value, element ) {
887
- return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test( value );
1277
+ return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test( value );
888
1278
  }, "Please specify a valid postal code" );
889
1279
 
890
1280
  /* Matches Italian postcode (CAP) */
891
1281
  $.validator.addMethod( "postalcodeIT", function( value, element ) {
892
- return this.optional( element ) || /^\d{5}$/.test( value );
1282
+ return this.optional( element ) || /^\d{5}$/.test( value );
893
1283
  }, "Please specify a valid postal code" );
894
1284
 
895
1285
  $.validator.addMethod( "postalcodeNL", function( value, element ) {
896
- return this.optional( element ) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test( value );
1286
+ return this.optional( element ) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test( value );
897
1287
  }, "Please specify a valid postal code" );
898
1288
 
899
1289
  // Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK)
900
1290
  $.validator.addMethod( "postcodeUK", function( value, element ) {
901
- return this.optional( element ) || /^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test( value );
1291
+ return this.optional( element ) || /^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test( value );
902
1292
  }, "Please specify a valid UK postcode" );
903
1293
 
904
1294
  /*
@@ -906,37 +1296,37 @@ $.validator.addMethod( "postcodeUK", function( value, element ) {
906
1296
  *
907
1297
  * The end result is that neither of these inputs:
908
1298
  *
909
- * <input class="productinfo" name="partnumber">
910
- * <input class="productinfo" name="description">
1299
+ * <input class="productinfo" name="partnumber">
1300
+ * <input class="productinfo" name="description">
911
1301
  *
912
- * ...will validate unless at least one of them is filled.
1302
+ * ...will validate unless at least one of them is filled.
913
1303
  *
914
- * partnumber: {require_from_group: [1,".productinfo"]},
1304
+ * partnumber: {require_from_group: [1,".productinfo"]},
915
1305
  * description: {require_from_group: [1,".productinfo"]}
916
1306
  *
917
1307
  * options[0]: number of fields that must be filled in the group
918
1308
  * options[1]: CSS selector that defines the group of conditionally required fields
919
1309
  */
920
1310
  $.validator.addMethod( "require_from_group", function( value, element, options ) {
921
- var $fields = $( options[ 1 ], element.form ),
922
- $fieldsFirst = $fields.eq( 0 ),
923
- validator = $fieldsFirst.data( "valid_req_grp" ) ? $fieldsFirst.data( "valid_req_grp" ) : $.extend( {}, this ),
924
- isValid = $fields.filter( function() {
925
- return validator.elementValue( this );
926
- } ).length >= options[ 0 ];
927
-
928
- // Store the cloned validator for future validation
929
- $fieldsFirst.data( "valid_req_grp", validator );
930
-
931
- // If element isn't being validated, run each require_from_group field's validation rules
932
- if ( !$( element ).data( "being_validated" ) ) {
933
- $fields.data( "being_validated", true );
934
- $fields.each( function() {
935
- validator.element( this );
936
- } );
937
- $fields.data( "being_validated", false );
938
- }
939
- return isValid;
1311
+ var $fields = $( options[ 1 ], element.form ),
1312
+ $fieldsFirst = $fields.eq( 0 ),
1313
+ validator = $fieldsFirst.data( "valid_req_grp" ) ? $fieldsFirst.data( "valid_req_grp" ) : $.extend( {}, this ),
1314
+ isValid = $fields.filter( function() {
1315
+ return validator.elementValue( this );
1316
+ } ).length >= options[ 0 ];
1317
+
1318
+ // Store the cloned validator for future validation
1319
+ $fieldsFirst.data( "valid_req_grp", validator );
1320
+
1321
+ // If element isn't being validated, run each require_from_group field's validation rules
1322
+ if ( !$( element ).data( "being_validated" ) ) {
1323
+ $fields.data( "being_validated", true );
1324
+ $fields.each( function() {
1325
+ validator.element( this );
1326
+ } );
1327
+ $fields.data( "being_validated", false );
1328
+ }
1329
+ return isValid;
940
1330
  }, $.validator.format( "Please fill at least {0} of these fields." ) );
941
1331
 
942
1332
  /*
@@ -945,42 +1335,42 @@ $.validator.addMethod( "require_from_group", function( value, element, options )
945
1335
  *
946
1336
  * The end result, is that none of these inputs:
947
1337
  *
948
- * <input class="productinfo" name="partnumber">
949
- * <input class="productinfo" name="description">
950
- * <input class="productinfo" name="color">
1338
+ * <input class="productinfo" name="partnumber">
1339
+ * <input class="productinfo" name="description">
1340
+ * <input class="productinfo" name="color">
951
1341
  *
952
- * ...will validate unless either at least two of them are filled,
953
- * OR none of them are.
1342
+ * ...will validate unless either at least two of them are filled,
1343
+ * OR none of them are.
954
1344
  *
955
- * partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
1345
+ * partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
956
1346
  * description: {skip_or_fill_minimum: [2,".productinfo"]},
957
- * color: {skip_or_fill_minimum: [2,".productinfo"]}
1347
+ * color: {skip_or_fill_minimum: [2,".productinfo"]}
958
1348
  *
959
1349
  * options[0]: number of fields that must be filled in the group
960
1350
  * options[1]: CSS selector that defines the group of conditionally required fields
961
1351
  *
962
1352
  */
963
1353
  $.validator.addMethod( "skip_or_fill_minimum", function( value, element, options ) {
964
- var $fields = $( options[ 1 ], element.form ),
965
- $fieldsFirst = $fields.eq( 0 ),
966
- validator = $fieldsFirst.data( "valid_skip" ) ? $fieldsFirst.data( "valid_skip" ) : $.extend( {}, this ),
967
- numberFilled = $fields.filter( function() {
968
- return validator.elementValue( this );
969
- } ).length,
970
- isValid = numberFilled === 0 || numberFilled >= options[ 0 ];
971
-
972
- // Store the cloned validator for future validation
973
- $fieldsFirst.data( "valid_skip", validator );
974
-
975
- // If element isn't being validated, run each skip_or_fill_minimum field's validation rules
976
- if ( !$( element ).data( "being_validated" ) ) {
977
- $fields.data( "being_validated", true );
978
- $fields.each( function() {
979
- validator.element( this );
980
- } );
981
- $fields.data( "being_validated", false );
982
- }
983
- return isValid;
1354
+ var $fields = $( options[ 1 ], element.form ),
1355
+ $fieldsFirst = $fields.eq( 0 ),
1356
+ validator = $fieldsFirst.data( "valid_skip" ) ? $fieldsFirst.data( "valid_skip" ) : $.extend( {}, this ),
1357
+ numberFilled = $fields.filter( function() {
1358
+ return validator.elementValue( this );
1359
+ } ).length,
1360
+ isValid = numberFilled === 0 || numberFilled >= options[ 0 ];
1361
+
1362
+ // Store the cloned validator for future validation
1363
+ $fieldsFirst.data( "valid_skip", validator );
1364
+
1365
+ // If element isn't being validated, run each skip_or_fill_minimum field's validation rules
1366
+ if ( !$( element ).data( "being_validated" ) ) {
1367
+ $fields.data( "being_validated", true );
1368
+ $fields.each( function() {
1369
+ validator.element( this );
1370
+ } );
1371
+ $fields.data( "being_validated", false );
1372
+ }
1373
+ return isValid;
984
1374
  }, $.validator.format( "Please either skip these fields or fill at least {0} of them." ) );
985
1375
 
986
1376
  /* Validates US States and/or Territories by @jdforsythe
@@ -1018,42 +1408,42 @@ $.validator.addMethod( "skip_or_fill_minimum", function( value, element, options
1018
1408
  *
1019
1409
  */
1020
1410
  $.validator.addMethod( "stateUS", function( value, element, options ) {
1021
- var isDefault = typeof options === "undefined",
1022
- caseSensitive = ( isDefault || typeof options.caseSensitive === "undefined" ) ? false : options.caseSensitive,
1023
- includeTerritories = ( isDefault || typeof options.includeTerritories === "undefined" ) ? false : options.includeTerritories,
1024
- includeMilitary = ( isDefault || typeof options.includeMilitary === "undefined" ) ? false : options.includeMilitary,
1025
- regex;
1026
-
1027
- if ( !includeTerritories && !includeMilitary ) {
1028
- regex = "^(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$";
1029
- } else if ( includeTerritories && includeMilitary ) {
1030
- regex = "^(A[AEKLPRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";
1031
- } else if ( includeTerritories ) {
1032
- regex = "^(A[KLRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";
1033
- } else {
1034
- regex = "^(A[AEKLPRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$";
1035
- }
1036
-
1037
- regex = caseSensitive ? new RegExp( regex ) : new RegExp( regex, "i" );
1038
- return this.optional( element ) || regex.test( value );
1411
+ var isDefault = typeof options === "undefined",
1412
+ caseSensitive = ( isDefault || typeof options.caseSensitive === "undefined" ) ? false : options.caseSensitive,
1413
+ includeTerritories = ( isDefault || typeof options.includeTerritories === "undefined" ) ? false : options.includeTerritories,
1414
+ includeMilitary = ( isDefault || typeof options.includeMilitary === "undefined" ) ? false : options.includeMilitary,
1415
+ regex;
1416
+
1417
+ if ( !includeTerritories && !includeMilitary ) {
1418
+ regex = "^(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$";
1419
+ } else if ( includeTerritories && includeMilitary ) {
1420
+ regex = "^(A[AEKLPRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";
1421
+ } else if ( includeTerritories ) {
1422
+ regex = "^(A[KLRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";
1423
+ } else {
1424
+ regex = "^(A[AEKLPRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$";
1425
+ }
1426
+
1427
+ regex = caseSensitive ? new RegExp( regex ) : new RegExp( regex, "i" );
1428
+ return this.optional( element ) || regex.test( value );
1039
1429
  }, "Please specify a valid state" );
1040
1430
 
1041
1431
  // TODO check if value starts with <, otherwise don't try stripping anything
1042
1432
  $.validator.addMethod( "strippedminlength", function( value, element, param ) {
1043
- return $( value ).text().length >= param;
1433
+ return $( value ).text().length >= param;
1044
1434
  }, $.validator.format( "Please enter at least {0} characters" ) );
1045
1435
 
1046
1436
  $.validator.addMethod( "time", function( value, element ) {
1047
- return this.optional( element ) || /^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test( value );
1437
+ return this.optional( element ) || /^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test( value );
1048
1438
  }, "Please enter a valid time, between 00:00 and 23:59" );
1049
1439
 
1050
1440
  $.validator.addMethod( "time12h", function( value, element ) {
1051
- return this.optional( element ) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test( value );
1441
+ return this.optional( element ) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test( value );
1052
1442
  }, "Please enter a valid time in 12-hour am/pm format" );
1053
1443
 
1054
1444
  // Same as url, but TLD is optional
1055
1445
  $.validator.addMethod( "url2", function( value, element ) {
1056
- 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 );
1446
+ 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 );
1057
1447
  }, $.validator.messages.url );
1058
1448
 
1059
1449
  /**
@@ -1069,54 +1459,54 @@ $.validator.addMethod( "url2", function( value, element ) {
1069
1459
  * @cat Plugins/Validate/Methods
1070
1460
  */
1071
1461
  $.validator.addMethod( "vinUS", function( v ) {
1072
- if ( v.length !== 17 ) {
1073
- return false;
1074
- }
1075
-
1076
- 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" ],
1077
- VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
1078
- FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
1079
- rs = 0,
1080
- i, n, d, f, cd, cdv;
1081
-
1082
- for ( i = 0; i < 17; i++ ) {
1083
- f = FL[ i ];
1084
- d = v.slice( i, i + 1 );
1085
- if ( i === 8 ) {
1086
- cdv = d;
1087
- }
1088
- if ( !isNaN( d ) ) {
1089
- d *= f;
1090
- } else {
1091
- for ( n = 0; n < LL.length; n++ ) {
1092
- if ( d.toUpperCase() === LL[ n ] ) {
1093
- d = VL[ n ];
1094
- d *= f;
1095
- if ( isNaN( cdv ) && n === 8 ) {
1096
- cdv = LL[ n ];
1097
- }
1098
- break;
1099
- }
1100
- }
1101
- }
1102
- rs += d;
1103
- }
1104
- cd = rs % 11;
1105
- if ( cd === 10 ) {
1106
- cd = "X";
1107
- }
1108
- if ( cd === cdv ) {
1109
- return true;
1110
- }
1111
- return false;
1462
+ if ( v.length !== 17 ) {
1463
+ return false;
1464
+ }
1465
+
1466
+ 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" ],
1467
+ VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
1468
+ FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
1469
+ rs = 0,
1470
+ i, n, d, f, cd, cdv;
1471
+
1472
+ for ( i = 0; i < 17; i++ ) {
1473
+ f = FL[ i ];
1474
+ d = v.slice( i, i + 1 );
1475
+ if ( i === 8 ) {
1476
+ cdv = d;
1477
+ }
1478
+ if ( !isNaN( d ) ) {
1479
+ d *= f;
1480
+ } else {
1481
+ for ( n = 0; n < LL.length; n++ ) {
1482
+ if ( d.toUpperCase() === LL[ n ] ) {
1483
+ d = VL[ n ];
1484
+ d *= f;
1485
+ if ( isNaN( cdv ) && n === 8 ) {
1486
+ cdv = LL[ n ];
1487
+ }
1488
+ break;
1489
+ }
1490
+ }
1491
+ }
1492
+ rs += d;
1493
+ }
1494
+ cd = rs % 11;
1495
+ if ( cd === 10 ) {
1496
+ cd = "X";
1497
+ }
1498
+ if ( cd === cdv ) {
1499
+ return true;
1500
+ }
1501
+ return false;
1112
1502
  }, "The specified vehicle identification number (VIN) is invalid." );
1113
1503
 
1114
1504
  $.validator.addMethod( "zipcodeUS", function( value, element ) {
1115
- return this.optional( element ) || /^\d{5}(-\d{4})?$/.test( value );
1505
+ return this.optional( element ) || /^\d{5}(-\d{4})?$/.test( value );
1116
1506
  }, "The specified US ZIP Code is invalid" );
1117
1507
 
1118
1508
  $.validator.addMethod( "ziprange", function( value, element ) {
1119
- return this.optional( element ) || /^90[2-5]\d\{2\}-\d{4}$/.test( value );
1509
+ return this.optional( element ) || /^90[2-5]\d\{2\}-\d{4}$/.test( value );
1120
1510
  }, "Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx" );
1121
1511
  return $;
1122
1512
  }));