bootstrap_validator-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +4 -0
- data/lib/bootstrap_validator-rails.rb +5 -0
- data/lib/bootstrap_validator-rails/engine.rb +6 -0
- data/vendor/javascripts/bootstrapValidator.js +1803 -0
- data/vendor/javascripts/language/de_DE.js +326 -0
- data/vendor/javascripts/language/en_US.js +327 -0
- data/vendor/javascripts/language/es_CL.js +326 -0
- data/vendor/javascripts/language/hu_HU.js +326 -0
- data/vendor/javascripts/language/vi_VN.js +322 -0
- data/vendor/javascripts/language/zh_CN.js +326 -0
- data/vendor/javascripts/language/zh_TW.js +326 -0
- data/vendor/javascripts/validator/base64.js +25 -0
- data/vendor/javascripts/validator/between.js +66 -0
- data/vendor/javascripts/validator/callback.js +40 -0
- data/vendor/javascripts/validator/choice.js +68 -0
- data/vendor/javascripts/validator/creditCard.js +103 -0
- data/vendor/javascripts/validator/cusip.js +55 -0
- data/vendor/javascripts/validator/cvv.js +116 -0
- data/vendor/javascripts/validator/date.js +118 -0
- data/vendor/javascripts/validator/different.js +41 -0
- data/vendor/javascripts/validator/digits.js +24 -0
- data/vendor/javascripts/validator/ean.js +40 -0
- data/vendor/javascripts/validator/emailAddress.js +31 -0
- data/vendor/javascripts/validator/file.js +69 -0
- data/vendor/javascripts/validator/greaterThan.js +61 -0
- data/vendor/javascripts/validator/grid.js +37 -0
- data/vendor/javascripts/validator/hex.js +25 -0
- data/vendor/javascripts/validator/hexColor.js +28 -0
- data/vendor/javascripts/validator/iban.js +246 -0
- data/vendor/javascripts/validator/id.js +815 -0
- data/vendor/javascripts/validator/identical.js +40 -0
- data/vendor/javascripts/validator/imei.js +44 -0
- data/vendor/javascripts/validator/integer.js +28 -0
- data/vendor/javascripts/validator/ip.js +48 -0
- data/vendor/javascripts/validator/isbn.js +86 -0
- data/vendor/javascripts/validator/isin.js +59 -0
- data/vendor/javascripts/validator/ismn.js +59 -0
- data/vendor/javascripts/validator/issn.js +46 -0
- data/vendor/javascripts/validator/lessThan.js +61 -0
- data/vendor/javascripts/validator/mac.js +25 -0
- data/vendor/javascripts/validator/notEmpty.js +32 -0
- data/vendor/javascripts/validator/numeric.js +39 -0
- data/vendor/javascripts/validator/phone.js +84 -0
- data/vendor/javascripts/validator/regexp.js +42 -0
- data/vendor/javascripts/validator/remote.js +70 -0
- data/vendor/javascripts/validator/rtn.js +38 -0
- data/vendor/javascripts/validator/sedol.js +40 -0
- data/vendor/javascripts/validator/siren.js +28 -0
- data/vendor/javascripts/validator/siret.js +38 -0
- data/vendor/javascripts/validator/step.js +64 -0
- data/vendor/javascripts/validator/stringCase.js +36 -0
- data/vendor/javascripts/validator/stringLength.js +81 -0
- data/vendor/javascripts/validator/uri.js +101 -0
- data/vendor/javascripts/validator/uuid.js +46 -0
- data/vendor/javascripts/validator/vat.js +1220 -0
- data/vendor/javascripts/validator/vin.js +49 -0
- data/vendor/javascripts/validator/zipCode.js +162 -0
- data/vendor/stylesheets/bootstrapValidator.css +21 -0
- metadata +130 -0
@@ -0,0 +1,815 @@
|
|
1
|
+
(function($) {
|
2
|
+
$.fn.bootstrapValidator.i18n.id = $.extend($.fn.bootstrapValidator.i18n.id || {}, {
|
3
|
+
'default': 'Please enter a valid identification number',
|
4
|
+
countryNotSupported: 'The country code %s is not supported',
|
5
|
+
country: 'Please enter a valid %s identification number',
|
6
|
+
countries: {
|
7
|
+
BA: 'Bosnia and Herzegovina',
|
8
|
+
BG: 'Bulgarian',
|
9
|
+
BR: 'Brazilian',
|
10
|
+
CH: 'Swiss',
|
11
|
+
CL: 'Chilean',
|
12
|
+
CZ: 'Czech',
|
13
|
+
DK: 'Danish',
|
14
|
+
EE: 'Estonian',
|
15
|
+
ES: 'Spanish',
|
16
|
+
FI: 'Finnish',
|
17
|
+
HR: 'Croatian',
|
18
|
+
IE: 'Irish',
|
19
|
+
IS: 'Iceland',
|
20
|
+
LT: 'Lithuanian',
|
21
|
+
LV: 'Latvian',
|
22
|
+
ME: 'Montenegro',
|
23
|
+
MK: 'Macedonian',
|
24
|
+
NL: 'Dutch',
|
25
|
+
RO: 'Romanian',
|
26
|
+
RS: 'Serbian',
|
27
|
+
SE: 'Swedish',
|
28
|
+
SI: 'Slovenian',
|
29
|
+
SK: 'Slovak',
|
30
|
+
SM: 'San Marino',
|
31
|
+
ZA: 'South African'
|
32
|
+
}
|
33
|
+
});
|
34
|
+
|
35
|
+
$.fn.bootstrapValidator.validators.id = {
|
36
|
+
html5Attributes: {
|
37
|
+
message: 'message',
|
38
|
+
country: 'country'
|
39
|
+
},
|
40
|
+
|
41
|
+
// Supported country codes
|
42
|
+
COUNTRY_CODES: [
|
43
|
+
'BA', 'BG', 'BR', 'CH', 'CL', 'CZ', 'DK', 'EE', 'ES', 'FI', 'HR', 'IE', 'IS', 'LT', 'LV', 'ME', 'MK', 'NL',
|
44
|
+
'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'ZA'
|
45
|
+
],
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Validate identification number in different countries
|
49
|
+
*
|
50
|
+
* @see http://en.wikipedia.org/wiki/National_identification_number
|
51
|
+
* @param {BootstrapValidator} validator The validator plugin instance
|
52
|
+
* @param {jQuery} $field Field element
|
53
|
+
* @param {Object} options Consist of key:
|
54
|
+
* - message: The invalid message
|
55
|
+
* - country: The ISO 3166-1 country code. It can be
|
56
|
+
* - One of country code defined in COUNTRY_CODES
|
57
|
+
* - Name of field which its value defines the country code
|
58
|
+
* - Name of callback function that returns the country code
|
59
|
+
* - A callback function that returns the country code
|
60
|
+
* @returns {Boolean|Object}
|
61
|
+
*/
|
62
|
+
validate: function(validator, $field, options) {
|
63
|
+
var value = $field.val();
|
64
|
+
if (value === '') {
|
65
|
+
return true;
|
66
|
+
}
|
67
|
+
|
68
|
+
var country = options.country;
|
69
|
+
if (!country) {
|
70
|
+
country = value.substr(0, 2);
|
71
|
+
} else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
|
72
|
+
// Determine the country code
|
73
|
+
country = validator.getDynamicOption($field, country);
|
74
|
+
}
|
75
|
+
|
76
|
+
if ($.inArray(country, this.COUNTRY_CODES) === -1) {
|
77
|
+
return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.id.countryNotSupported, country) };
|
78
|
+
}
|
79
|
+
|
80
|
+
var method = ['_', country.toLowerCase()].join('');
|
81
|
+
return this[method](value)
|
82
|
+
? true
|
83
|
+
: {
|
84
|
+
valid: false,
|
85
|
+
message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.id.country, $.fn.bootstrapValidator.i18n.id.countries[country.toUpperCase()])
|
86
|
+
};
|
87
|
+
},
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Validate Unique Master Citizen Number which uses in
|
91
|
+
* - Bosnia and Herzegovina (country code: BA)
|
92
|
+
* - Macedonia (MK)
|
93
|
+
* - Montenegro (ME)
|
94
|
+
* - Serbia (RS)
|
95
|
+
* - Slovenia (SI)
|
96
|
+
*
|
97
|
+
* @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
|
98
|
+
* @param {String} value The ID
|
99
|
+
* @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
|
100
|
+
* @returns {Boolean}
|
101
|
+
*/
|
102
|
+
_validateJMBG: function(value, countryCode) {
|
103
|
+
if (!/^\d{13}$/.test(value)) {
|
104
|
+
return false;
|
105
|
+
}
|
106
|
+
var day = parseInt(value.substr(0, 2), 10),
|
107
|
+
month = parseInt(value.substr(2, 2), 10),
|
108
|
+
year = parseInt(value.substr(4, 3), 10),
|
109
|
+
rr = parseInt(value.substr(7, 2), 10),
|
110
|
+
k = parseInt(value.substr(12, 1), 10);
|
111
|
+
|
112
|
+
// Validate date of birth
|
113
|
+
// FIXME: Validate the year of birth
|
114
|
+
if (day > 31 || month > 12) {
|
115
|
+
return false;
|
116
|
+
}
|
117
|
+
|
118
|
+
// Validate checksum
|
119
|
+
var sum = 0;
|
120
|
+
for (var i = 0; i < 6; i++) {
|
121
|
+
sum += (7 - i) * (parseInt(value.charAt(i), 10) + parseInt(value.charAt(i + 6), 10));
|
122
|
+
}
|
123
|
+
sum = 11 - sum % 11;
|
124
|
+
if (sum === 10 || sum === 11) {
|
125
|
+
sum = 0;
|
126
|
+
}
|
127
|
+
if (sum !== k) {
|
128
|
+
return false;
|
129
|
+
}
|
130
|
+
|
131
|
+
// Validate political region
|
132
|
+
// rr is the political region of birth, which can be in ranges:
|
133
|
+
// 10-19: Bosnia and Herzegovina
|
134
|
+
// 20-29: Montenegro
|
135
|
+
// 30-39: Croatia (not used anymore)
|
136
|
+
// 41-49: Macedonia
|
137
|
+
// 50-59: Slovenia (only 50 is used)
|
138
|
+
// 70-79: Central Serbia
|
139
|
+
// 80-89: Serbian province of Vojvodina
|
140
|
+
// 90-99: Kosovo
|
141
|
+
switch (countryCode.toUpperCase()) {
|
142
|
+
case 'BA':
|
143
|
+
return (10 <= rr && rr <= 19);
|
144
|
+
case 'MK':
|
145
|
+
return (41 <= rr && rr <= 49);
|
146
|
+
case 'ME':
|
147
|
+
return (20 <= rr && rr <= 29);
|
148
|
+
case 'RS':
|
149
|
+
return (70 <= rr && rr <= 99);
|
150
|
+
case 'SI':
|
151
|
+
return (50 <= rr && rr <= 59);
|
152
|
+
default:
|
153
|
+
return true;
|
154
|
+
}
|
155
|
+
},
|
156
|
+
|
157
|
+
_ba: function(value) {
|
158
|
+
return this._validateJMBG(value, 'BA');
|
159
|
+
},
|
160
|
+
_mk: function(value) {
|
161
|
+
return this._validateJMBG(value, 'MK');
|
162
|
+
},
|
163
|
+
_me: function(value) {
|
164
|
+
return this._validateJMBG(value, 'ME');
|
165
|
+
},
|
166
|
+
_rs: function(value) {
|
167
|
+
return this._validateJMBG(value, 'RS');
|
168
|
+
},
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Examples: 0101006500006
|
172
|
+
*/
|
173
|
+
_si: function(value) {
|
174
|
+
return this._validateJMBG(value, 'SI');
|
175
|
+
},
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Validate Bulgarian national identification number (EGN)
|
179
|
+
* Examples:
|
180
|
+
* - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
|
181
|
+
* - Invalid: 8019010008
|
182
|
+
*
|
183
|
+
* @see http://en.wikipedia.org/wiki/Uniform_civil_number
|
184
|
+
* @param {String} value The ID
|
185
|
+
* @returns {Boolean}
|
186
|
+
*/
|
187
|
+
_bg: function(value) {
|
188
|
+
if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
|
189
|
+
return false;
|
190
|
+
}
|
191
|
+
value = value.replace(/\s/g, '');
|
192
|
+
// Check the birth date
|
193
|
+
var year = parseInt(value.substr(0, 2), 10) + 1900,
|
194
|
+
month = parseInt(value.substr(2, 2), 10),
|
195
|
+
day = parseInt(value.substr(4, 2), 10);
|
196
|
+
if (month > 40) {
|
197
|
+
year += 100;
|
198
|
+
month -= 40;
|
199
|
+
} else if (month > 20) {
|
200
|
+
year -= 100;
|
201
|
+
month -= 20;
|
202
|
+
}
|
203
|
+
|
204
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
|
205
|
+
return false;
|
206
|
+
}
|
207
|
+
|
208
|
+
var sum = 0,
|
209
|
+
weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
|
210
|
+
for (var i = 0; i < 9; i++) {
|
211
|
+
sum += parseInt(value.charAt(i), 10) * weight[i];
|
212
|
+
}
|
213
|
+
sum = (sum % 11) % 10;
|
214
|
+
return (sum + '' === value.substr(9, 1));
|
215
|
+
},
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Validate Brazilian national identification number (CPF)
|
219
|
+
* Examples:
|
220
|
+
* - Valid: 39053344705, 390.533.447-05, 111.444.777-35
|
221
|
+
* - Invalid: 231.002.999-00
|
222
|
+
*
|
223
|
+
* @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
|
224
|
+
* @param {String} value The ID
|
225
|
+
* @returns {Boolean}
|
226
|
+
*/
|
227
|
+
_br: function(value) {
|
228
|
+
if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
|
229
|
+
return false;
|
230
|
+
}
|
231
|
+
if (!/^\d{11}$/.test(value) && !/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(value)) {
|
232
|
+
return false;
|
233
|
+
}
|
234
|
+
value = value.replace(/\./g, '').replace(/-/g, '');
|
235
|
+
|
236
|
+
var d1 = 0;
|
237
|
+
for (var i = 0; i < 9; i++) {
|
238
|
+
d1 += (10 - i) * parseInt(value.charAt(i), 10);
|
239
|
+
}
|
240
|
+
d1 = 11 - d1 % 11;
|
241
|
+
if (d1 === 10 || d1 === 11) {
|
242
|
+
d1 = 0;
|
243
|
+
}
|
244
|
+
if (d1 + '' !== value.charAt(9)) {
|
245
|
+
return false;
|
246
|
+
}
|
247
|
+
|
248
|
+
var d2 = 0;
|
249
|
+
for (i = 0; i < 10; i++) {
|
250
|
+
d2 += (11 - i) * parseInt(value.charAt(i), 10);
|
251
|
+
}
|
252
|
+
d2 = 11 - d2 % 11;
|
253
|
+
if (d2 === 10 || d2 === 11) {
|
254
|
+
d2 = 0;
|
255
|
+
}
|
256
|
+
|
257
|
+
return (d2 + '' === value.charAt(10));
|
258
|
+
},
|
259
|
+
|
260
|
+
/**
|
261
|
+
* Validate Swiss Social Security Number (AHV-Nr/No AVS)
|
262
|
+
* Examples:
|
263
|
+
* - Valid: 756.1234.5678.95, 7561234567895
|
264
|
+
*
|
265
|
+
* @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
|
266
|
+
* @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
|
267
|
+
* @param {String} value The ID
|
268
|
+
* @returns {Boolean}
|
269
|
+
*/
|
270
|
+
_ch: function(value) {
|
271
|
+
if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
|
272
|
+
return false;
|
273
|
+
}
|
274
|
+
value = value.replace(/\D/g, '').substr(3);
|
275
|
+
var length = value.length,
|
276
|
+
sum = 0,
|
277
|
+
weight = (length === 8) ? [3, 1] : [1, 3];
|
278
|
+
for (var i = 0; i < length - 1; i++) {
|
279
|
+
sum += parseInt(value.charAt(i), 10) * weight[i % 2];
|
280
|
+
}
|
281
|
+
sum = 10 - sum % 10;
|
282
|
+
return (sum + '' === value.charAt(length - 1));
|
283
|
+
},
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Validate Chilean national identification number (RUN/RUT)
|
287
|
+
* Examples:
|
288
|
+
* - Valid: 76086428-5, 22060449-7, 12531909-2
|
289
|
+
*
|
290
|
+
* @see http://en.wikipedia.org/wiki/National_identification_number#Chile
|
291
|
+
* @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
|
292
|
+
* @param {String} value The ID
|
293
|
+
* @returns {Boolean}
|
294
|
+
*/
|
295
|
+
_cl: function(value) {
|
296
|
+
if (!/^\d{7,8}[-]{0,1}[0-9K]$/i.test(value)) {
|
297
|
+
return false;
|
298
|
+
}
|
299
|
+
value = value.replace(/\-/g, '');
|
300
|
+
while (value.length < 9) {
|
301
|
+
value = '0' + value;
|
302
|
+
}
|
303
|
+
var sum = 0,
|
304
|
+
weight = [3, 2, 7, 6, 5, 4, 3, 2];
|
305
|
+
for (var i = 0; i < 8; i++) {
|
306
|
+
sum += parseInt(value.charAt(i), 10) * weight[i];
|
307
|
+
}
|
308
|
+
sum = 11 - sum % 11;
|
309
|
+
if (sum === 11) {
|
310
|
+
sum = 0;
|
311
|
+
} else if (sum === 10) {
|
312
|
+
sum = 'K';
|
313
|
+
}
|
314
|
+
return sum + '' === value.charAt(8).toUpperCase();
|
315
|
+
},
|
316
|
+
|
317
|
+
/**
|
318
|
+
* Validate Czech national identification number (RC)
|
319
|
+
* Examples:
|
320
|
+
* - Valid: 7103192745, 991231123
|
321
|
+
* - Invalid: 1103492745, 590312123
|
322
|
+
*
|
323
|
+
* @param {String} value The ID
|
324
|
+
* @returns {Boolean}
|
325
|
+
*/
|
326
|
+
_cz: function(value) {
|
327
|
+
if (!/^\d{9,10}$/.test(value)) {
|
328
|
+
return false;
|
329
|
+
}
|
330
|
+
var year = 1900 + parseInt(value.substr(0, 2), 10),
|
331
|
+
month = parseInt(value.substr(2, 2), 10) % 50 % 20,
|
332
|
+
day = parseInt(value.substr(4, 2), 10);
|
333
|
+
if (value.length === 9) {
|
334
|
+
if (year >= 1980) {
|
335
|
+
year -= 100;
|
336
|
+
}
|
337
|
+
if (year > 1953) {
|
338
|
+
return false;
|
339
|
+
}
|
340
|
+
} else if (year < 1954) {
|
341
|
+
year += 100;
|
342
|
+
}
|
343
|
+
|
344
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
|
345
|
+
return false;
|
346
|
+
}
|
347
|
+
|
348
|
+
// Check that the birth date is not in the future
|
349
|
+
if (value.length === 10) {
|
350
|
+
var check = parseInt(value.substr(0, 9), 10) % 11;
|
351
|
+
if (year < 1985) {
|
352
|
+
check = check % 10;
|
353
|
+
}
|
354
|
+
return (check + '' === value.substr(9, 1));
|
355
|
+
}
|
356
|
+
|
357
|
+
return true;
|
358
|
+
},
|
359
|
+
|
360
|
+
/**
|
361
|
+
* Validate Danish Personal Identification number (CPR)
|
362
|
+
* Examples:
|
363
|
+
* - Valid: 2110625629, 211062-5629
|
364
|
+
* - Invalid: 511062-5629
|
365
|
+
*
|
366
|
+
* @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
|
367
|
+
* @param {String} value The ID
|
368
|
+
* @returns {Boolean}
|
369
|
+
*/
|
370
|
+
_dk: function(value) {
|
371
|
+
if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
|
372
|
+
return false;
|
373
|
+
}
|
374
|
+
value = value.replace(/-/g, '');
|
375
|
+
var day = parseInt(value.substr(0, 2), 10),
|
376
|
+
month = parseInt(value.substr(2, 2), 10),
|
377
|
+
year = parseInt(value.substr(4, 2), 10);
|
378
|
+
|
379
|
+
switch (true) {
|
380
|
+
case ('5678'.indexOf(value.charAt(6)) !== -1 && year >= 58):
|
381
|
+
year += 1800;
|
382
|
+
break;
|
383
|
+
case ('0123'.indexOf(value.charAt(6)) !== -1):
|
384
|
+
case ('49'.indexOf(value.charAt(6)) !== -1 && year >= 37):
|
385
|
+
year += 1900;
|
386
|
+
break;
|
387
|
+
default:
|
388
|
+
year += 2000;
|
389
|
+
break;
|
390
|
+
}
|
391
|
+
|
392
|
+
return $.fn.bootstrapValidator.helpers.date(year, month, day);
|
393
|
+
},
|
394
|
+
|
395
|
+
/**
|
396
|
+
* Validate Estonian Personal Identification Code (isikukood)
|
397
|
+
* Examples:
|
398
|
+
* - Valid: 37605030299
|
399
|
+
*
|
400
|
+
* @see http://et.wikipedia.org/wiki/Isikukood
|
401
|
+
* @param {String} value The ID
|
402
|
+
* @returns {Boolean}
|
403
|
+
*/
|
404
|
+
_ee: function(value) {
|
405
|
+
// Use the same format as Lithuanian Personal Code
|
406
|
+
return this._lt(value);
|
407
|
+
},
|
408
|
+
|
409
|
+
/**
|
410
|
+
* Validate Spanish personal identity code (DNI)
|
411
|
+
* Support i) DNI (for Spanish citizens) and ii) NIE (for foreign people)
|
412
|
+
*
|
413
|
+
* Examples:
|
414
|
+
* - Valid: i) 54362315K, 54362315-K; ii) X2482300W, X-2482300W, X-2482300-W
|
415
|
+
* - Invalid: i) 54362315Z; ii) X-2482300A
|
416
|
+
*
|
417
|
+
* @see https://en.wikipedia.org/wiki/National_identification_number#Spain
|
418
|
+
* @param {String} value The ID
|
419
|
+
* @returns {Boolean}
|
420
|
+
*/
|
421
|
+
_es: function(value) {
|
422
|
+
if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]$/.test(value) // DNI
|
423
|
+
&& !/^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-Z]$/.test(value)) { // NIE
|
424
|
+
return false;
|
425
|
+
}
|
426
|
+
|
427
|
+
value = value.replace(/-/g, '');
|
428
|
+
var index = 'XYZ'.indexOf(value.charAt(0));
|
429
|
+
if (index !== -1) {
|
430
|
+
// It is NIE number
|
431
|
+
value = index + value.substr(1) + '';
|
432
|
+
}
|
433
|
+
|
434
|
+
var check = parseInt(value.substr(0, 8), 10);
|
435
|
+
check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
|
436
|
+
return (check === value.substr(8, 1));
|
437
|
+
},
|
438
|
+
|
439
|
+
/**
|
440
|
+
* Validate Finnish Personal Identity Code (HETU)
|
441
|
+
* Examples:
|
442
|
+
* - Valid: 311280-888Y, 131052-308T
|
443
|
+
* - Invalid: 131052-308U, 310252-308Y
|
444
|
+
*
|
445
|
+
* @param {String} value The ID
|
446
|
+
* @returns {Boolean}
|
447
|
+
*/
|
448
|
+
_fi: function(value) {
|
449
|
+
if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
|
450
|
+
return false;
|
451
|
+
}
|
452
|
+
var day = parseInt(value.substr(0, 2), 10),
|
453
|
+
month = parseInt(value.substr(2, 2), 10),
|
454
|
+
year = parseInt(value.substr(4, 2), 10),
|
455
|
+
centuries = {
|
456
|
+
'+': 1800,
|
457
|
+
'-': 1900,
|
458
|
+
'A': 2000
|
459
|
+
};
|
460
|
+
year = centuries[value.charAt(6)] + year;
|
461
|
+
|
462
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
|
463
|
+
return false;
|
464
|
+
}
|
465
|
+
|
466
|
+
var individual = parseInt(value.substr(7, 3), 10);
|
467
|
+
if (individual < 2) {
|
468
|
+
return false;
|
469
|
+
}
|
470
|
+
var n = value.substr(0, 6) + value.substr(7, 3) + '';
|
471
|
+
n = parseInt(n, 10);
|
472
|
+
return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) === value.charAt(10);
|
473
|
+
},
|
474
|
+
|
475
|
+
/**
|
476
|
+
* Validate Croatian personal identification number (OIB)
|
477
|
+
* Examples:
|
478
|
+
* - Valid: 33392005961
|
479
|
+
* - Invalid: 33392005962
|
480
|
+
*
|
481
|
+
* @param {String} value The ID
|
482
|
+
* @returns {Boolean}
|
483
|
+
*/
|
484
|
+
_hr: function(value) {
|
485
|
+
if (!/^[0-9]{11}$/.test(value)) {
|
486
|
+
return false;
|
487
|
+
}
|
488
|
+
return $.fn.bootstrapValidator.helpers.mod11And10(value);
|
489
|
+
},
|
490
|
+
|
491
|
+
/**
|
492
|
+
* Validate Irish Personal Public Service Number (PPS)
|
493
|
+
* Examples:
|
494
|
+
* - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
|
495
|
+
* - Invalid: 6433435E, 6433435VH
|
496
|
+
*
|
497
|
+
* @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
|
498
|
+
* @param {String} value The ID
|
499
|
+
* @returns {Boolean}
|
500
|
+
*/
|
501
|
+
_ie: function(value) {
|
502
|
+
if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
|
503
|
+
return false;
|
504
|
+
}
|
505
|
+
|
506
|
+
var getCheckDigit = function(value) {
|
507
|
+
while (value.length < 7) {
|
508
|
+
value = '0' + value;
|
509
|
+
}
|
510
|
+
var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
|
511
|
+
sum = 0;
|
512
|
+
for (var i = 0; i < 7; i++) {
|
513
|
+
sum += parseInt(value.charAt(i), 10) * (8 - i);
|
514
|
+
}
|
515
|
+
sum += 9 * alphabet.indexOf(value.substr(7));
|
516
|
+
return alphabet[sum % 23];
|
517
|
+
};
|
518
|
+
|
519
|
+
// 2013 format
|
520
|
+
if (value.length === 9 && ('A' === value.charAt(8) || 'H' === value.charAt(8))) {
|
521
|
+
return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
|
522
|
+
}
|
523
|
+
// The old format
|
524
|
+
else {
|
525
|
+
return value.charAt(7) === getCheckDigit(value.substr(0, 7));
|
526
|
+
}
|
527
|
+
},
|
528
|
+
|
529
|
+
/**
|
530
|
+
* Validate Iceland national identification number (Kennitala)
|
531
|
+
* Examples:
|
532
|
+
* - Valid: 120174-3399, 1201743399, 0902862349
|
533
|
+
*
|
534
|
+
* @see http://en.wikipedia.org/wiki/Kennitala
|
535
|
+
* @param {String} value The ID
|
536
|
+
* @returns {Boolean}
|
537
|
+
*/
|
538
|
+
_is: function(value) {
|
539
|
+
if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
|
540
|
+
return false;
|
541
|
+
}
|
542
|
+
value = value.replace(/-/g, '');
|
543
|
+
var day = parseInt(value.substr(0, 2), 10),
|
544
|
+
month = parseInt(value.substr(2, 2), 10),
|
545
|
+
year = parseInt(value.substr(4, 2), 10),
|
546
|
+
century = parseInt(value.charAt(9), 10);
|
547
|
+
|
548
|
+
year = (century === 9) ? (1900 + year) : ((20 + century) * 100 + year);
|
549
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
|
550
|
+
return false;
|
551
|
+
}
|
552
|
+
// Validate the check digit
|
553
|
+
var sum = 0,
|
554
|
+
weight = [3, 2, 7, 6, 5, 4, 3, 2];
|
555
|
+
for (var i = 0; i < 8; i++) {
|
556
|
+
sum += parseInt(value.charAt(i), 10) * weight[i];
|
557
|
+
}
|
558
|
+
sum = 11 - sum % 11;
|
559
|
+
return (sum + '' === value.charAt(8));
|
560
|
+
},
|
561
|
+
|
562
|
+
/**
|
563
|
+
* Validate Lithuanian Personal Code (Asmens kodas)
|
564
|
+
* Examples:
|
565
|
+
* - Valid: 38703181745
|
566
|
+
* - Invalid: 38703181746, 78703181745, 38703421745
|
567
|
+
*
|
568
|
+
* @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
|
569
|
+
* @see http://www.adomas.org/midi2007/pcode.html
|
570
|
+
* @param {String} value The ID
|
571
|
+
* @returns {Boolean}
|
572
|
+
*/
|
573
|
+
_lt: function(value) {
|
574
|
+
if (!/^[0-9]{11}$/.test(value)) {
|
575
|
+
return false;
|
576
|
+
}
|
577
|
+
var gender = parseInt(value.charAt(0), 10),
|
578
|
+
year = parseInt(value.substr(1, 2), 10),
|
579
|
+
month = parseInt(value.substr(3, 2), 10),
|
580
|
+
day = parseInt(value.substr(5, 2), 10),
|
581
|
+
century = (gender % 2 === 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
|
582
|
+
year = century * 100 + year;
|
583
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
|
584
|
+
return false;
|
585
|
+
}
|
586
|
+
|
587
|
+
// Validate the check digit
|
588
|
+
var sum = 0,
|
589
|
+
weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
|
590
|
+
for (var i = 0; i < 10; i++) {
|
591
|
+
sum += parseInt(value.charAt(i), 10) * weight[i];
|
592
|
+
}
|
593
|
+
sum = sum % 11;
|
594
|
+
if (sum !== 10) {
|
595
|
+
return sum + '' === value.charAt(10);
|
596
|
+
}
|
597
|
+
|
598
|
+
// Re-calculate the check digit
|
599
|
+
sum = 0;
|
600
|
+
weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
|
601
|
+
for (i = 0; i < 10; i++) {
|
602
|
+
sum += parseInt(value.charAt(i), 10) * weight[i];
|
603
|
+
}
|
604
|
+
sum = sum % 11;
|
605
|
+
if (sum === 10) {
|
606
|
+
sum = 0;
|
607
|
+
}
|
608
|
+
return (sum + '' === value.charAt(10));
|
609
|
+
},
|
610
|
+
|
611
|
+
/**
|
612
|
+
* Validate Latvian Personal Code (Personas kods)
|
613
|
+
* Examples:
|
614
|
+
* - Valid: 161175-19997, 16117519997
|
615
|
+
* - Invalid: 161375-19997
|
616
|
+
*
|
617
|
+
* @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
|
618
|
+
* @param {String} value The ID
|
619
|
+
* @returns {Boolean}
|
620
|
+
*/
|
621
|
+
_lv: function(value) {
|
622
|
+
if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
|
623
|
+
return false;
|
624
|
+
}
|
625
|
+
value = value.replace(/\D/g, '');
|
626
|
+
// Check birth date
|
627
|
+
var day = parseInt(value.substr(0, 2), 10),
|
628
|
+
month = parseInt(value.substr(2, 2), 10),
|
629
|
+
year = parseInt(value.substr(4, 2), 10);
|
630
|
+
year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
|
631
|
+
|
632
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
|
633
|
+
return false;
|
634
|
+
}
|
635
|
+
|
636
|
+
// Check personal code
|
637
|
+
var sum = 0,
|
638
|
+
weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
|
639
|
+
for (var i = 0; i < 10; i++) {
|
640
|
+
sum += parseInt(value.charAt(i), 10) * weight[i];
|
641
|
+
}
|
642
|
+
sum = (sum + 1) % 11 % 10;
|
643
|
+
return (sum + '' === value.charAt(10));
|
644
|
+
},
|
645
|
+
|
646
|
+
/**
|
647
|
+
* Validate Dutch national identification number (BSN)
|
648
|
+
* Examples:
|
649
|
+
* - Valid: 111222333, 941331490, 9413.31.490
|
650
|
+
* - Invalid: 111252333
|
651
|
+
*
|
652
|
+
* @see https://nl.wikipedia.org/wiki/Burgerservicenummer
|
653
|
+
* @param {String} value The ID
|
654
|
+
* @returns {Boolean}
|
655
|
+
*/
|
656
|
+
_nl: function(value) {
|
657
|
+
while (value.length < 9) {
|
658
|
+
value = '0' + value;
|
659
|
+
}
|
660
|
+
if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
|
661
|
+
return false;
|
662
|
+
}
|
663
|
+
value = value.replace(/\./g, '');
|
664
|
+
if (parseInt(value, 10) === 0) {
|
665
|
+
return false;
|
666
|
+
}
|
667
|
+
var sum = 0,
|
668
|
+
length = value.length;
|
669
|
+
for (var i = 0; i < length - 1; i++) {
|
670
|
+
sum += (9 - i) * parseInt(value.charAt(i), 10);
|
671
|
+
}
|
672
|
+
sum = sum % 11;
|
673
|
+
if (sum === 10) {
|
674
|
+
sum = 0;
|
675
|
+
}
|
676
|
+
return (sum + '' === value.charAt(length - 1));
|
677
|
+
},
|
678
|
+
|
679
|
+
/**
|
680
|
+
* Validate Romanian numerical personal code (CNP)
|
681
|
+
* Examples:
|
682
|
+
* - Valid: 1630615123457, 1800101221144
|
683
|
+
* - Invalid: 8800101221144, 1632215123457, 1630615123458
|
684
|
+
*
|
685
|
+
* @see http://en.wikipedia.org/wiki/National_identification_number#Romania
|
686
|
+
* @param {String} value The ID
|
687
|
+
* @returns {Boolean}
|
688
|
+
*/
|
689
|
+
_ro: function(value) {
|
690
|
+
if (!/^[0-9]{13}$/.test(value)) {
|
691
|
+
return false;
|
692
|
+
}
|
693
|
+
var gender = parseInt(value.charAt(0), 10);
|
694
|
+
if (gender === 0 || gender === 7 || gender === 8) {
|
695
|
+
return false;
|
696
|
+
}
|
697
|
+
|
698
|
+
// Determine the date of birth
|
699
|
+
var year = parseInt(value.substr(1, 2), 10),
|
700
|
+
month = parseInt(value.substr(3, 2), 10),
|
701
|
+
day = parseInt(value.substr(5, 2), 10),
|
702
|
+
// The year of date is determined base on the gender
|
703
|
+
centuries = {
|
704
|
+
'1': 1900, // Male born between 1900 and 1999
|
705
|
+
'2': 1900, // Female born between 1900 and 1999
|
706
|
+
'3': 1800, // Male born between 1800 and 1899
|
707
|
+
'4': 1800, // Female born between 1800 and 1899
|
708
|
+
'5': 2000, // Male born after 2000
|
709
|
+
'6': 2000 // Female born after 2000
|
710
|
+
};
|
711
|
+
if (day > 31 && month > 12) {
|
712
|
+
return false;
|
713
|
+
}
|
714
|
+
if (gender !== 9) {
|
715
|
+
year = centuries[gender + ''] + year;
|
716
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
|
717
|
+
return false;
|
718
|
+
}
|
719
|
+
}
|
720
|
+
|
721
|
+
// Validate the check digit
|
722
|
+
var sum = 0,
|
723
|
+
weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
|
724
|
+
length = value.length;
|
725
|
+
for (var i = 0; i < length - 1; i++) {
|
726
|
+
sum += parseInt(value.charAt(i), 10) * weight[i];
|
727
|
+
}
|
728
|
+
sum = sum % 11;
|
729
|
+
if (sum === 10) {
|
730
|
+
sum = 1;
|
731
|
+
}
|
732
|
+
return (sum + '' === value.charAt(length - 1));
|
733
|
+
},
|
734
|
+
|
735
|
+
/**
|
736
|
+
* Validate Swedish personal identity number (personnummer)
|
737
|
+
* Examples:
|
738
|
+
* - Valid: 8112289874, 811228-9874, 811228+9874
|
739
|
+
* - Invalid: 811228-9873
|
740
|
+
*
|
741
|
+
* @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
|
742
|
+
* @param {String} value The ID
|
743
|
+
* @returns {Boolean}
|
744
|
+
*/
|
745
|
+
_se: function(value) {
|
746
|
+
if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
|
747
|
+
return false;
|
748
|
+
}
|
749
|
+
value = value.replace(/[^0-9]/g, '');
|
750
|
+
|
751
|
+
var year = parseInt(value.substr(0, 2), 10) + 1900,
|
752
|
+
month = parseInt(value.substr(2, 2), 10),
|
753
|
+
day = parseInt(value.substr(4, 2), 10);
|
754
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
|
755
|
+
return false;
|
756
|
+
}
|
757
|
+
|
758
|
+
// Validate the last check digit
|
759
|
+
return $.fn.bootstrapValidator.helpers.luhn(value);
|
760
|
+
},
|
761
|
+
|
762
|
+
/**
|
763
|
+
* Validate Slovak national identifier number (RC)
|
764
|
+
* Examples:
|
765
|
+
* - Valid: 7103192745, 991231123
|
766
|
+
* - Invalid: 7103192746, 1103492745
|
767
|
+
*
|
768
|
+
* @param {String} value The ID
|
769
|
+
* @returns {Boolean}
|
770
|
+
*/
|
771
|
+
_sk: function(value) {
|
772
|
+
// Slovakia uses the same format as Czech Republic
|
773
|
+
return this._cz(value);
|
774
|
+
},
|
775
|
+
|
776
|
+
/**
|
777
|
+
* Validate San Marino citizen number
|
778
|
+
*
|
779
|
+
* @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
|
780
|
+
* @param {String} value The ID
|
781
|
+
* @returns {Boolean}
|
782
|
+
*/
|
783
|
+
_sm: function(value) {
|
784
|
+
return /^\d{5}$/.test(value);
|
785
|
+
},
|
786
|
+
|
787
|
+
/**
|
788
|
+
* Validate South African ID
|
789
|
+
* Example:
|
790
|
+
* - Valid: 8001015009087
|
791
|
+
* - Invalid: 8001015009287, 8001015009086
|
792
|
+
*
|
793
|
+
* @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
|
794
|
+
* @param {String} value The ID
|
795
|
+
* @returns {Boolean}
|
796
|
+
*/
|
797
|
+
_za: function(value) {
|
798
|
+
if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
|
799
|
+
return false;
|
800
|
+
}
|
801
|
+
var year = parseInt(value.substr(0, 2), 10),
|
802
|
+
currentYear = new Date().getFullYear() % 100,
|
803
|
+
month = parseInt(value.substr(2, 2), 10),
|
804
|
+
day = parseInt(value.substr(4, 2), 10);
|
805
|
+
year = (year >= currentYear) ? (year + 1900) : (year + 2000);
|
806
|
+
|
807
|
+
if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
|
808
|
+
return false;
|
809
|
+
}
|
810
|
+
|
811
|
+
// Validate the last check digit
|
812
|
+
return $.fn.bootstrapValidator.helpers.luhn(value);
|
813
|
+
}
|
814
|
+
};
|
815
|
+
}(window.jQuery));
|