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.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/jquery-validation-rails.gemspec +11 -11
- data/lib/jquery/validation/rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.validate.additional-methods.js +1015 -625
- data/vendor/assets/javascripts/jquery.validate.js +1610 -1534
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ar.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_az.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_bg.js +13 -1
- data/vendor/assets/javascripts/jquery.validate.localization/messages_bn_BD.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ca.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_cs.js +14 -1
- data/vendor/assets/javascripts/jquery.validate.localization/messages_da.js +30 -4
- data/vendor/assets/javascripts/jquery.validate.localization/messages_de.js +66 -4
- data/vendor/assets/javascripts/jquery.validate.localization/messages_el.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_es.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_es_AR.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_es_PE.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_et.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_eu.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_fa.js +19 -6
- data/vendor/assets/javascripts/jquery.validate.localization/messages_fi.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_fr.js +15 -1
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ge.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_gl.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_he.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_hr.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_hu.js +14 -1
- data/vendor/assets/javascripts/jquery.validate.localization/messages_hy_AM.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_id.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_is.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_it.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ja.js +13 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ka.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_kk.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ko.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_lt.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_lv.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_mk.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_my.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_nl.js +13 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_no.js +20 -8
- data/vendor/assets/javascripts/jquery.validate.localization/messages_pl.js +14 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_pt_BR.js +31 -16
- data/vendor/assets/javascripts/jquery.validate.localization/messages_pt_PT.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ro.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ru.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_sd.js +35 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_si.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_sk.js +14 -1
- data/vendor/assets/javascripts/jquery.validate.localization/messages_sl.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_sr.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_sr_lat.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_sv.js +15 -1
- data/vendor/assets/javascripts/jquery.validate.localization/messages_th.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_tj.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_tr.js +13 -1
- data/vendor/assets/javascripts/jquery.validate.localization/messages_uk.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_ur.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_vi.js +13 -1
- data/vendor/assets/javascripts/jquery.validate.localization/messages_zh.js +13 -0
- data/vendor/assets/javascripts/jquery.validate.localization/messages_zh_TW.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/methods_de.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/methods_es_CL.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/methods_fi.js +12 -0
- data/vendor/assets/javascripts/jquery.validate.localization/methods_it.js +24 -0
- data/vendor/assets/javascripts/jquery.validate.localization/methods_nl.js +15 -0
- data/vendor/assets/javascripts/jquery.validate.localization/methods_pt.js +12 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5c5c3f12a30de196e894ed0b762565b7f5586dd7be072110a699788d440f1454
|
4
|
+
data.tar.gz: de2580358ccc0fe520f2db82a49030fcc54cbcb896b3a094217e557bbe40e868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0af1a78001598b1970e525349737f0064e57e2acb2486bd3a65e9fa5c8c9c41b1f02afa22d675432ba3f7d42b79ddb07adcd0184d27ed13942a94f281eea8873
|
7
|
+
data.tar.gz: fdb8cadc40d7a0e1397b26363cf61c9d0e24344b66ca6c9c9c898f30fa9fb2e558f149c0d8256445127f5559c8b65d94908ba4e1fbbd4141e7a281189a37a01f
|
data/README.md
CHANGED
@@ -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 =
|
9
|
+
gem.name = 'jquery-validation-rails'
|
10
10
|
gem.version = Jquery::Validation::Rails::VERSION
|
11
|
-
gem.authors = [
|
12
|
-
gem.email = [
|
13
|
-
gem.description =
|
14
|
-
gem.summary =
|
15
|
-
gem.homepage =
|
16
|
-
gem.license =
|
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 = [
|
20
|
+
gem.require_paths = ['lib']
|
21
21
|
end
|
@@ -1,92 +1,124 @@
|
|
1
1
|
/*!
|
2
|
-
* jQuery Validation Plugin v1.
|
2
|
+
* jQuery Validation Plugin v1.19.0
|
3
3
|
*
|
4
|
-
*
|
4
|
+
* https://jqueryvalidation.org/
|
5
5
|
*
|
6
|
-
* Copyright (c)
|
6
|
+
* Copyright (c) 2018 Jörn Zaefferer
|
7
7
|
* Released under the MIT license
|
8
8
|
*/
|
9
9
|
(function( factory ) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
21
|
+
function stripHtml( value ) {
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
// Remove html tags and space chars
|
24
|
+
return value.replace( /<.[^<>]*?>/g, " " ).replace( / | /gi, " " )
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
// Remove punctuation
|
27
|
+
.replace( /[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "" );
|
28
|
+
}
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
213
|
-
|
214
|
-
|
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
|
-
|
218
|
-
|
297
|
+
// Removing special characters from value
|
298
|
+
value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );
|
219
299
|
|
220
|
-
|
221
|
-
|
300
|
+
// Checking value to have 11 digits only
|
301
|
+
if ( value.length !== 11 ) {
|
302
|
+
return false;
|
303
|
+
}
|
222
304
|
|
223
|
-
|
224
|
-
|
305
|
+
var sum = 0, dsc = 0, firstChar,
|
306
|
+
firstCN, secondCN, i, j, v;
|
225
307
|
|
226
|
-
|
227
|
-
odd_sum += n < 10 ? n : n - 9;
|
308
|
+
firstChar = value.charAt( 0 );
|
228
309
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
even_sum += n;
|
233
|
-
}
|
234
|
-
}
|
310
|
+
if ( new Array( 12 ).join( firstChar ) === value ) {
|
311
|
+
return false;
|
312
|
+
}
|
235
313
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
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
|
-
|
242
|
-
|
243
|
-
|
319
|
+
firstCN = sum % 11;
|
320
|
+
if ( firstCN >= 10 ) {
|
321
|
+
firstCN = 0;
|
322
|
+
dsc = 2;
|
323
|
+
}
|
244
324
|
|
245
|
-
|
246
|
-
|
247
|
-
|
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
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
330
|
+
secondCN = sum % 11;
|
331
|
+
if ( secondCN >= 10 ) {
|
332
|
+
secondCN = 0;
|
333
|
+
} else {
|
334
|
+
secondCN = secondCN - dsc;
|
335
|
+
}
|
253
336
|
|
254
|
-
|
337
|
+
return ( String( firstCN ).concat( secondCN ) === value.substr( -2 ) );
|
255
338
|
|
256
|
-
}, "Please specify a valid
|
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
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
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
|
-
//
|
320
|
-
// based on
|
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
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
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
|
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
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
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
|
-
|
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
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
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
|
-
|
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
|
-
|
523
|
-
|
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
|
-
|
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
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
704
|
-
|
705
|
-
|
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
|
-
|
993
|
+
$.validator.addMethod( "nieES", function( value, element ) {
|
994
|
+
"use strict";
|
718
995
|
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
number;
|
996
|
+
if ( this.optional( element ) ) {
|
997
|
+
return true;
|
998
|
+
}
|
723
999
|
|
724
|
-
|
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
|
-
|
727
|
-
|
728
|
-
|
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
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
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
|
-
|
1019
|
+
number = value.length === 9 ? value.substr( 0, 8 ) : value.substr( 0, 9 );
|
739
1020
|
|
740
|
-
|
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
|
-
|
1028
|
+
$.validator.addMethod( "nifES", function( value, element ) {
|
1029
|
+
"use strict";
|
749
1030
|
|
750
|
-
|
1031
|
+
if ( this.optional( element ) ) {
|
1032
|
+
return true;
|
1033
|
+
}
|
751
1034
|
|
752
|
-
|
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
|
-
|
758
|
-
|
759
|
-
|
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
|
-
|
763
|
-
|
764
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
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
|
-
|
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
|
-
|
821
|
-
|
822
|
-
|
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
|
-
|
835
|
-
|
836
|
-
|
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
|
-
|
857
|
-
|
858
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
*
|
910
|
-
*
|
1299
|
+
* <input class="productinfo" name="partnumber">
|
1300
|
+
* <input class="productinfo" name="description">
|
911
1301
|
*
|
912
|
-
*
|
1302
|
+
* ...will validate unless at least one of them is filled.
|
913
1303
|
*
|
914
|
-
* partnumber:
|
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
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
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
|
-
*
|
949
|
-
*
|
950
|
-
*
|
1338
|
+
* <input class="productinfo" name="partnumber">
|
1339
|
+
* <input class="productinfo" name="description">
|
1340
|
+
* <input class="productinfo" name="color">
|
951
1341
|
*
|
952
|
-
*
|
953
|
-
*
|
1342
|
+
* ...will validate unless either at least two of them are filled,
|
1343
|
+
* OR none of them are.
|
954
1344
|
*
|
955
|
-
* partnumber:
|
1345
|
+
* partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
|
956
1346
|
* description: {skip_or_fill_minimum: [2,".productinfo"]},
|
957
|
-
* color:
|
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
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
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
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
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
|
-
|
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
|
-
|
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
|
}));
|