Subversion-Projekte lars-tiefland.ci

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
776 lars 1
/*!
2
 * jQuery Validation Plugin v1.14.0
3
 *
4
 * http://jqueryvalidation.org/
5
 *
6
 * Copyright (c) 2015 Jörn Zaefferer
7
 * Released under the MIT license
8
 */
9
(function( factory ) {
10
	if ( typeof define === "function" && define.amd ) {
11
		define( ["jquery", "./jquery.validate"], factory );
12
	} else {
13
		factory( jQuery );
14
	}
15
}(function( $ ) {
16
 
17
(function() {
18
 
19
	function stripHtml(value) {
20
		// remove html tags and space chars
21
		return value.replace(/<.[^<>]*?>/g, " ").replace(/&nbsp;|&#160;/gi, " ")
22
		// remove punctuation
23
		.replace(/[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "");
24
	}
25
 
26
	$.validator.addMethod("maxWords", function(value, element, params) {
27
		return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length <= params;
28
	}, $.validator.format("Please enter {0} words or less."));
29
 
30
	$.validator.addMethod("minWords", function(value, element, params) {
31
		return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params;
32
	}, $.validator.format("Please enter at least {0} words."));
33
 
34
	$.validator.addMethod("rangeWords", function(value, element, params) {
35
		var valueStripped = stripHtml(value),
36
			regex = /\b\w+\b/g;
37
		return this.optional(element) || valueStripped.match(regex).length >= params[0] && valueStripped.match(regex).length <= params[1];
38
	}, $.validator.format("Please enter between {0} and {1} words."));
39
 
40
}());
41
 
42
// Accept a value from a file input based on a required mimetype
43
$.validator.addMethod("accept", function(value, element, param) {
44
	// Split mime on commas in case we have multiple types we can accept
45
	var typeParam = typeof param === "string" ? param.replace(/\s/g, "").replace(/,/g, "|") : "image/*",
46
	optionalValue = this.optional(element),
47
	i, file;
48
 
49
	// Element is optional
50
	if (optionalValue) {
51
		return optionalValue;
52
	}
53
 
54
	if ($(element).attr("type") === "file") {
55
		// If we are using a wildcard, make it regex friendly
56
		typeParam = typeParam.replace(/\*/g, ".*");
57
 
58
		// Check if the element has a FileList before checking each file
59
		if (element.files && element.files.length) {
60
			for (i = 0; i < element.files.length; i++) {
61
				file = element.files[i];
62
 
63
				// Grab the mimetype from the loaded file, verify it matches
64
				if (!file.type.match(new RegExp( "\\.?(" + typeParam + ")$", "i"))) {
65
					return false;
66
				}
67
			}
68
		}
69
	}
70
 
71
	// Either return true because we've validated each file, or because the
72
	// browser does not support element.files and the FileList feature
73
	return true;
74
}, $.validator.format("Please enter a value with a valid mimetype."));
75
 
76
$.validator.addMethod("alphanumeric", function(value, element) {
77
	return this.optional(element) || /^\w+$/i.test(value);
78
}, "Letters, numbers, and underscores only please");
79
 
80
/*
81
 * Dutch bank account numbers (not 'giro' numbers) have 9 digits
82
 * and pass the '11 check'.
83
 * We accept the notation with spaces, as that is common.
84
 * acceptable: 123456789 or 12 34 56 789
85
 */
86
$.validator.addMethod("bankaccountNL", function(value, element) {
87
	if (this.optional(element)) {
88
		return true;
89
	}
90
	if (!(/^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test(value))) {
91
		return false;
92
	}
93
	// now '11 check'
94
	var account = value.replace(/ /g, ""), // remove spaces
95
		sum = 0,
96
		len = account.length,
97
		pos, factor, digit;
98
	for ( pos = 0; pos < len; pos++ ) {
99
		factor = len - pos;
100
		digit = account.substring(pos, pos + 1);
101
		sum = sum + factor * digit;
102
	}
103
	return sum % 11 === 0;
104
}, "Please specify a valid bank account number");
105
 
106
$.validator.addMethod("bankorgiroaccountNL", function(value, element) {
107
	return this.optional(element) ||
108
			($.validator.methods.bankaccountNL.call(this, value, element)) ||
109
			($.validator.methods.giroaccountNL.call(this, value, element));
110
}, "Please specify a valid bank or giro account number");
111
 
112
/**
113
 * BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
114
 *
115
 * BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
116
 *
117
 * BIC definition in detail:
118
 * - First 4 characters - bank code (only letters)
119
 * - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
120
 * - Next 2 characters - location code (letters and digits)
121
 *   a. shall not start with '0' or '1'
122
 *   b. second character must be a letter ('O' is not allowed) or one of the following digits ('0' for test (therefore not allowed), '1' for passive participant and '2' for active participant)
123
 * - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)
124
 */
125
$.validator.addMethod("bic", function(value, element) {
126
    return this.optional( element ) || /^([A-Z]{6}[A-Z2-9][A-NP-Z1-2])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test( value );
127
}, "Please specify a valid BIC code");
128
 
129
/*
130
 * Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
131
 * Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
132
 */
133
$.validator.addMethod( "cifES", function( value ) {
134
	"use strict";
135
 
136
	var num = [],
137
		controlDigit, sum, i, count, tmp, secondDigit;
138
 
139
	value = value.toUpperCase();
140
 
141
	// Quick format test
142
	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}$)" ) ) {
143
		return false;
144
	}
145
 
146
	for ( i = 0; i < 9; i++ ) {
147
		num[ i ] = parseInt( value.charAt( i ), 10 );
148
	}
149
 
150
	// Algorithm for checking CIF codes
151
	sum = num[ 2 ] + num[ 4 ] + num[ 6 ];
152
	for ( count = 1; count < 8; count += 2 ) {
153
		tmp = ( 2 * num[ count ] ).toString();
154
		secondDigit = tmp.charAt( 1 );
155
 
156
		sum += parseInt( tmp.charAt( 0 ), 10 ) + ( secondDigit === "" ? 0 : parseInt( secondDigit, 10 ) );
157
	}
158
 
159
	/* The first (position 1) is a letter following the following criteria:
160
	 *	A. Corporations
161
	 *	B. LLCs
162
	 *	C. General partnerships
163
	 *	D. Companies limited partnerships
164
	 *	E. Communities of goods
165
	 *	F. Cooperative Societies
166
	 *	G. Associations
167
	 *	H. Communities of homeowners in horizontal property regime
168
	 *	J. Civil Societies
169
	 *	K. Old format
170
	 *	L. Old format
171
	 *	M. Old format
172
	 *	N. Nonresident entities
173
	 *	P. Local authorities
174
	 *	Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions
175
	 *	R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)
176
	 *	S. Organs of State Administration and regions
177
	 *	V. Agrarian Transformation
178
	 *	W. Permanent establishments of non-resident in Spain
179
	 */
180
	if ( /^[ABCDEFGHJNPQRSUVW]{1}/.test( value ) ) {
181
		sum += "";
182
		controlDigit = 10 - parseInt( sum.charAt( sum.length - 1 ), 10 );
183
		value += controlDigit;
184
		return ( num[ 8 ].toString() === String.fromCharCode( 64 + controlDigit ) || num[ 8 ].toString() === value.charAt( value.length - 1 ) );
185
	}
186
 
187
	return false;
188
 
189
}, "Please specify a valid CIF number." );
190
 
191
/*
192
 * Brazillian CPF number (Cadastrado de Pessoas Físicas) is the equivalent of a Brazilian tax registration number.
193
 * CPF numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.
194
 */
195
$.validator.addMethod("cpfBR", function(value) {
196
	// Removing special characters from value
197
	value = value.replace(/([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "");
198
 
199
	// Checking value to have 11 digits only
200
	if (value.length !== 11) {
201
		return false;
202
	}
203
 
204
	var sum = 0,
205
		firstCN, secondCN, checkResult, i;
206
 
207
	firstCN = parseInt(value.substring(9, 10), 10);
208
	secondCN = parseInt(value.substring(10, 11), 10);
209
 
210
	checkResult = function(sum, cn) {
211
		var result = (sum * 10) % 11;
212
		if ((result === 10) || (result === 11)) {result = 0;}
213
		return (result === cn);
214
	};
215
 
216
	// Checking for dump data
217
	if (value === "" ||
218
		value === "00000000000" ||
219
		value === "11111111111" ||
220
		value === "22222222222" ||
221
		value === "33333333333" ||
222
		value === "44444444444" ||
223
		value === "55555555555" ||
224
		value === "66666666666" ||
225
		value === "77777777777" ||
226
		value === "88888888888" ||
227
		value === "99999999999"
228
	) {
229
		return false;
230
	}
231
 
232
	// Step 1 - using first Check Number:
233
	for ( i = 1; i <= 9; i++ ) {
234
		sum = sum + parseInt(value.substring(i - 1, i), 10) * (11 - i);
235
	}
236
 
237
	// If first Check Number (CN) is valid, move to Step 2 - using second Check Number:
238
	if ( checkResult(sum, firstCN) ) {
239
		sum = 0;
240
		for ( i = 1; i <= 10; i++ ) {
241
			sum = sum + parseInt(value.substring(i - 1, i), 10) * (12 - i);
242
		}
243
		return checkResult(sum, secondCN);
244
	}
245
	return false;
246
 
247
}, "Please specify a valid CPF number");
248
 
249
/* NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
250
 * Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
251
 * Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
252
 */
253
$.validator.addMethod("creditcardtypes", function(value, element, param) {
254
	if (/[^0-9\-]+/.test(value)) {
255
		return false;
256
	}
257
 
258
	value = value.replace(/\D/g, "");
259
 
260
	var validTypes = 0x0000;
261
 
262
	if (param.mastercard) {
263
		validTypes |= 0x0001;
264
	}
265
	if (param.visa) {
266
		validTypes |= 0x0002;
267
	}
268
	if (param.amex) {
269
		validTypes |= 0x0004;
270
	}
271
	if (param.dinersclub) {
272
		validTypes |= 0x0008;
273
	}
274
	if (param.enroute) {
275
		validTypes |= 0x0010;
276
	}
277
	if (param.discover) {
278
		validTypes |= 0x0020;
279
	}
280
	if (param.jcb) {
281
		validTypes |= 0x0040;
282
	}
283
	if (param.unknown) {
284
		validTypes |= 0x0080;
285
	}
286
	if (param.all) {
287
		validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
288
	}
289
	if (validTypes & 0x0001 && /^(5[12345])/.test(value)) { //mastercard
290
		return value.length === 16;
291
	}
292
	if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa
293
		return value.length === 16;
294
	}
295
	if (validTypes & 0x0004 && /^(3[47])/.test(value)) { //amex
296
		return value.length === 15;
297
	}
298
	if (validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test(value)) { //dinersclub
299
		return value.length === 14;
300
	}
301
	if (validTypes & 0x0010 && /^(2(014|149))/.test(value)) { //enroute
302
		return value.length === 15;
303
	}
304
	if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover
305
		return value.length === 16;
306
	}
307
	if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb
308
		return value.length === 16;
309
	}
310
	if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb
311
		return value.length === 15;
312
	}
313
	if (validTypes & 0x0080) { //unknown
314
		return true;
315
	}
316
	return false;
317
}, "Please enter a valid credit card number.");
318
 
319
/**
320
 * Validates currencies with any given symbols by @jameslouiz
321
 * Symbols can be optional or required. Symbols required by default
322
 *
323
 * Usage examples:
324
 *  currency: ["£", false] - Use false for soft currency validation
325
 *  currency: ["$", false]
326
 *  currency: ["RM", false] - also works with text based symbols such as "RM" - Malaysia Ringgit etc
327
 *
328
 *  <input class="currencyInput" name="currencyInput">
329
 *
330
 * Soft symbol checking
331
 *  currencyInput: {
332
 *     currency: ["$", false]
333
 *  }
334
 *
335
 * Strict symbol checking (default)
336
 *  currencyInput: {
337
 *     currency: "$"
338
 *     //OR
339
 *     currency: ["$", true]
340
 *  }
341
 *
342
 * Multiple Symbols
343
 *  currencyInput: {
344
 *     currency: "$,£,¢"
345
 *  }
346
 */
347
$.validator.addMethod("currency", function(value, element, param) {
348
    var isParamString = typeof param === "string",
349
        symbol = isParamString ? param : param[0],
350
        soft = isParamString ? true : param[1],
351
        regex;
352
 
353
    symbol = symbol.replace(/,/g, "");
354
    symbol = soft ? symbol + "]" : symbol + "]?";
355
    regex = "^[" + symbol + "([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$";
356
    regex = new RegExp(regex);
357
    return this.optional(element) || regex.test(value);
358
 
359
}, "Please specify a valid currency");
360
 
361
$.validator.addMethod("dateFA", function(value, element) {
362
	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);
363
}, $.validator.messages.date);
364
 
365
/**
366
 * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
367
 *
368
 * @example $.validator.methods.date("01/01/1900")
369
 * @result true
370
 *
371
 * @example $.validator.methods.date("01/13/1990")
372
 * @result false
373
 *
374
 * @example $.validator.methods.date("01.01.1900")
375
 * @result false
376
 *
377
 * @example <input name="pippo" class="{dateITA:true}" />
378
 * @desc Declares an optional input element whose value must be a valid date.
379
 *
380
 * @name $.validator.methods.dateITA
381
 * @type Boolean
382
 * @cat Plugins/Validate/Methods
383
 */
384
$.validator.addMethod("dateITA", function(value, element) {
385
	var check = false,
386
		re = /^\d{1,2}\/\d{1,2}\/\d{4}$/,
387
		adata, gg, mm, aaaa, xdata;
388
	if ( re.test(value)) {
389
		adata = value.split("/");
390
		gg = parseInt(adata[0], 10);
391
		mm = parseInt(adata[1], 10);
392
		aaaa = parseInt(adata[2], 10);
393
		xdata = new Date(Date.UTC(aaaa, mm - 1, gg, 12, 0, 0, 0));
394
		if ( ( xdata.getUTCFullYear() === aaaa ) && ( xdata.getUTCMonth () === mm - 1 ) && ( xdata.getUTCDate() === gg ) ) {
395
			check = true;
396
		} else {
397
			check = false;
398
		}
399
	} else {
400
		check = false;
401
	}
402
	return this.optional(element) || check;
403
}, $.validator.messages.date);
404
 
405
$.validator.addMethod("dateNL", function(value, element) {
406
	return this.optional(element) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(value);
407
}, $.validator.messages.date);
408
 
409
// Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept
410
$.validator.addMethod("extension", function(value, element, param) {
411
	param = typeof param === "string" ? param.replace(/,/g, "|") : "png|jpe?g|gif";
412
	return this.optional(element) || value.match(new RegExp("\\.(" + param + ")$", "i"));
413
}, $.validator.format("Please enter a value with a valid extension."));
414
 
415
/**
416
 * Dutch giro account numbers (not bank numbers) have max 7 digits
417
 */
418
$.validator.addMethod("giroaccountNL", function(value, element) {
419
	return this.optional(element) || /^[0-9]{1,7}$/.test(value);
420
}, "Please specify a valid giro account number");
421
 
422
/**
423
 * IBAN is the international bank account number.
424
 * It has a country - specific format, that is checked here too
425
 */
426
$.validator.addMethod("iban", function(value, element) {
427
	// some quick simple tests to prevent needless work
428
	if (this.optional(element)) {
429
		return true;
430
	}
431
 
432
	// remove spaces and to upper case
433
	var iban = value.replace(/ /g, "").toUpperCase(),
434
		ibancheckdigits = "",
435
		leadingZeroes = true,
436
		cRest = "",
437
		cOperator = "",
438
		countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;
439
 
440
	// check the country code and find the country specific format
441
	countrycode = iban.substring(0, 2);
442
	bbancountrypatterns = {
443
		"AL": "\\d{8}[\\dA-Z]{16}",
444
		"AD": "\\d{8}[\\dA-Z]{12}",
445
		"AT": "\\d{16}",
446
		"AZ": "[\\dA-Z]{4}\\d{20}",
447
		"BE": "\\d{12}",
448
		"BH": "[A-Z]{4}[\\dA-Z]{14}",
449
		"BA": "\\d{16}",
450
		"BR": "\\d{23}[A-Z][\\dA-Z]",
451
		"BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
452
		"CR": "\\d{17}",
453
		"HR": "\\d{17}",
454
		"CY": "\\d{8}[\\dA-Z]{16}",
455
		"CZ": "\\d{20}",
456
		"DK": "\\d{14}",
457
		"DO": "[A-Z]{4}\\d{20}",
458
		"EE": "\\d{16}",
459
		"FO": "\\d{14}",
460
		"FI": "\\d{14}",
461
		"FR": "\\d{10}[\\dA-Z]{11}\\d{2}",
462
		"GE": "[\\dA-Z]{2}\\d{16}",
463
		"DE": "\\d{18}",
464
		"GI": "[A-Z]{4}[\\dA-Z]{15}",
465
		"GR": "\\d{7}[\\dA-Z]{16}",
466
		"GL": "\\d{14}",
467
		"GT": "[\\dA-Z]{4}[\\dA-Z]{20}",
468
		"HU": "\\d{24}",
469
		"IS": "\\d{22}",
470
		"IE": "[\\dA-Z]{4}\\d{14}",
471
		"IL": "\\d{19}",
472
		"IT": "[A-Z]\\d{10}[\\dA-Z]{12}",
473
		"KZ": "\\d{3}[\\dA-Z]{13}",
474
		"KW": "[A-Z]{4}[\\dA-Z]{22}",
475
		"LV": "[A-Z]{4}[\\dA-Z]{13}",
476
		"LB": "\\d{4}[\\dA-Z]{20}",
477
		"LI": "\\d{5}[\\dA-Z]{12}",
478
		"LT": "\\d{16}",
479
		"LU": "\\d{3}[\\dA-Z]{13}",
480
		"MK": "\\d{3}[\\dA-Z]{10}\\d{2}",
481
		"MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
482
		"MR": "\\d{23}",
483
		"MU": "[A-Z]{4}\\d{19}[A-Z]{3}",
484
		"MC": "\\d{10}[\\dA-Z]{11}\\d{2}",
485
		"MD": "[\\dA-Z]{2}\\d{18}",
486
		"ME": "\\d{18}",
487
		"NL": "[A-Z]{4}\\d{10}",
488
		"NO": "\\d{11}",
489
		"PK": "[\\dA-Z]{4}\\d{16}",
490
		"PS": "[\\dA-Z]{4}\\d{21}",
491
		"PL": "\\d{24}",
492
		"PT": "\\d{21}",
493
		"RO": "[A-Z]{4}[\\dA-Z]{16}",
494
		"SM": "[A-Z]\\d{10}[\\dA-Z]{12}",
495
		"SA": "\\d{2}[\\dA-Z]{18}",
496
		"RS": "\\d{18}",
497
		"SK": "\\d{20}",
498
		"SI": "\\d{15}",
499
		"ES": "\\d{20}",
500
		"SE": "\\d{20}",
501
		"CH": "\\d{5}[\\dA-Z]{12}",
502
		"TN": "\\d{20}",
503
		"TR": "\\d{5}[\\dA-Z]{17}",
504
		"AE": "\\d{3}\\d{16}",
505
		"GB": "[A-Z]{4}\\d{14}",
506
		"VG": "[\\dA-Z]{4}\\d{16}"
507
	};
508
 
509
	bbanpattern = bbancountrypatterns[countrycode];
510
	// As new countries will start using IBAN in the
511
	// future, we only check if the countrycode is known.
512
	// This prevents false negatives, while almost all
513
	// false positives introduced by this, will be caught
514
	// by the checksum validation below anyway.
515
	// Strict checking should return FALSE for unknown
516
	// countries.
517
	if (typeof bbanpattern !== "undefined") {
518
		ibanregexp = new RegExp("^[A-Z]{2}\\d{2}" + bbanpattern + "$", "");
519
		if (!(ibanregexp.test(iban))) {
520
			return false; // invalid country specific format
521
		}
522
	}
523
 
524
	// now check the checksum, first convert to digits
525
	ibancheck = iban.substring(4, iban.length) + iban.substring(0, 4);
526
	for (i = 0; i < ibancheck.length; i++) {
527
		charAt = ibancheck.charAt(i);
528
		if (charAt !== "0") {
529
			leadingZeroes = false;
530
		}
531
		if (!leadingZeroes) {
532
			ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(charAt);
533
		}
534
	}
535
 
536
	// calculate the result of: ibancheckdigits % 97
537
	for (p = 0; p < ibancheckdigits.length; p++) {
538
		cChar = ibancheckdigits.charAt(p);
539
		cOperator = "" + cRest + "" + cChar;
540
		cRest = cOperator % 97;
541
	}
542
	return cRest === 1;
543
}, "Please specify a valid IBAN");
544
 
545
$.validator.addMethod("integer", function(value, element) {
546
	return this.optional(element) || /^-?\d+$/.test(value);
547
}, "A positive or negative non-decimal number please");
548
 
549
$.validator.addMethod("ipv4", function(value, element) {
550
	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);
551
}, "Please enter a valid IP v4 address.");
552
 
553
$.validator.addMethod("ipv6", function(value, element) {
554
	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);
555
}, "Please enter a valid IP v6 address.");
556
 
557
$.validator.addMethod("lettersonly", function(value, element) {
558
	return this.optional(element) || /^[a-z]+$/i.test(value);
559
}, "Letters only please");
560
 
561
$.validator.addMethod("letterswithbasicpunc", function(value, element) {
562
	return this.optional(element) || /^[a-z\-.,()'"\s]+$/i.test(value);
563
}, "Letters or punctuation only please");
564
 
565
$.validator.addMethod("mobileNL", function(value, element) {
566
	return this.optional(element) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test(value);
567
}, "Please specify a valid mobile number");
568
 
569
/* For UK phone functions, do the following server side processing:
570
 * Compare original input with this RegEx pattern:
571
 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
572
 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
573
 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
574
 * A number of very detailed GB telephone number RegEx patterns can also be found at:
575
 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
576
 */
577
$.validator.addMethod("mobileUK", function(phone_number, element) {
578
	phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
579
	return this.optional(element) || phone_number.length > 9 &&
580
		phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/);
581
}, "Please specify a valid mobile number");
582
 
583
/*
584
 * The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain
585
 */
586
$.validator.addMethod( "nieES", function( value ) {
587
	"use strict";
588
 
589
	value = value.toUpperCase();
590
 
591
	// Basic format test
592
	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}$)" ) ) {
593
		return false;
594
	}
595
 
596
	// Test NIE
597
	//T
598
	if ( /^[T]{1}/.test( value ) ) {
599
		return ( value[ 8 ] === /^[T]{1}[A-Z0-9]{8}$/.test( value ) );
600
	}
601
 
602
	//XYZ
603
	if ( /^[XYZ]{1}/.test( value ) ) {
604
		return (
605
			value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt(
606
				value.replace( "X", "0" )
607
					.replace( "Y", "1" )
608
					.replace( "Z", "2" )
609
					.substring( 0, 8 ) % 23
610
			)
611
		);
612
	}
613
 
614
	return false;
615
 
616
}, "Please specify a valid NIE number." );
617
 
618
/*
619
 * The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
620
 */
621
$.validator.addMethod( "nifES", function( value ) {
622
	"use strict";
623
 
624
	value = value.toUpperCase();
625
 
626
	// Basic format test
627
	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}$)") ) {
628
		return false;
629
	}
630
 
631
	// Test NIF
632
	if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {
633
		return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );
634
	}
635
	// Test specials NIF (starts with K, L or M)
636
	if ( /^[KLM]{1}/.test( value ) ) {
637
		return ( value[ 8 ] === String.fromCharCode( 64 ) );
638
	}
639
 
640
	return false;
641
 
642
}, "Please specify a valid NIF number." );
643
 
644
jQuery.validator.addMethod( "notEqualTo", function( value, element, param ) {
645
	return this.optional(element) || !$.validator.methods.equalTo.call( this, value, element, param );
646
}, "Please enter a different value, values must not be the same." );
647
 
648
$.validator.addMethod("nowhitespace", function(value, element) {
649
	return this.optional(element) || /^\S+$/i.test(value);
650
}, "No white space please");
651
 
652
/**
653
* Return true if the field value matches the given format RegExp
654
*
655
* @example $.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)
656
* @result true
657
*
658
* @example $.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)
659
* @result false
660
*
661
* @name $.validator.methods.pattern
662
* @type Boolean
663
* @cat Plugins/Validate/Methods
664
*/
665
$.validator.addMethod("pattern", function(value, element, param) {
666
	if (this.optional(element)) {
667
		return true;
668
	}
669
	if (typeof param === "string") {
670
		param = new RegExp("^(?:" + param + ")$");
671
	}
672
	return param.test(value);
673
}, "Invalid format.");
674
 
675
/**
676
 * Dutch phone numbers have 10 digits (or 11 and start with +31).
677
 */
678
$.validator.addMethod("phoneNL", function(value, element) {
679
	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);
680
}, "Please specify a valid phone number.");
681
 
682
/* For UK phone functions, do the following server side processing:
683
 * Compare original input with this RegEx pattern:
684
 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
685
 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
686
 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
687
 * A number of very detailed GB telephone number RegEx patterns can also be found at:
688
 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
689
 */
690
$.validator.addMethod("phoneUK", function(phone_number, element) {
691
	phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
692
	return this.optional(element) || phone_number.length > 9 &&
693
		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})$/);
694
}, "Please specify a valid phone number");
695
 
696
/**
697
 * matches US phone number format
698
 *
699
 * where the area code may not start with 1 and the prefix may not start with 1
700
 * allows '-' or ' ' as a separator and allows parens around area code
701
 * some people may want to put a '1' in front of their number
702
 *
703
 * 1(212)-999-2345 or
704
 * 212 999 2344 or
705
 * 212-999-0983
706
 *
707
 * but not
708
 * 111-123-5434
709
 * and not
710
 * 212 123 4567
711
 */
712
$.validator.addMethod("phoneUS", function(phone_number, element) {
713
	phone_number = phone_number.replace(/\s+/g, "");
714
	return this.optional(element) || phone_number.length > 9 &&
715
		phone_number.match(/^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/);
716
}, "Please specify a valid phone number");
717
 
718
/* For UK phone functions, do the following server side processing:
719
 * Compare original input with this RegEx pattern:
720
 * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
721
 * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
722
 * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
723
 * A number of very detailed GB telephone number RegEx patterns can also be found at:
724
 * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
725
 */
726
//Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
727
$.validator.addMethod("phonesUK", function(phone_number, element) {
728
	phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
729
	return this.optional(element) || phone_number.length > 9 &&
730
		phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/);
731
}, "Please specify a valid uk phone number");
732
 
733
/**
734
 * Matches a valid Canadian Postal Code
735
 *
736
 * @example jQuery.validator.methods.postalCodeCA( "H0H 0H0", element )
737
 * @result true
738
 *
739
 * @example jQuery.validator.methods.postalCodeCA( "H0H0H0", element )
740
 * @result false
741
 *
742
 * @name jQuery.validator.methods.postalCodeCA
743
 * @type Boolean
744
 * @cat Plugins/Validate/Methods
745
 */
746
$.validator.addMethod( "postalCodeCA", function( value, element ) {
747
	return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d$/.test( value );
748
}, "Please specify a valid postal code" );
749
 
750
/*
751
* Valida CEPs do brasileiros:
752
*
753
* Formatos aceitos:
754
* 99999-999
755
* 99.999-999
756
* 99999999
757
*/
758
$.validator.addMethod("postalcodeBR", function(cep_value, element) {
759
	return this.optional(element) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );
760
}, "Informe um CEP válido.");
761
 
762
/* Matches Italian postcode (CAP) */
763
$.validator.addMethod("postalcodeIT", function(value, element) {
764
	return this.optional(element) || /^\d{5}$/.test(value);
765
}, "Please specify a valid postal code");
766
 
767
$.validator.addMethod("postalcodeNL", function(value, element) {
768
	return this.optional(element) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test(value);
769
}, "Please specify a valid postal code");
770
 
771
// Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK)
772
$.validator.addMethod("postcodeUK", function(value, element) {
773
	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);
774
}, "Please specify a valid UK postcode");
775
 
776
/*
777
 * Lets you say "at least X inputs that match selector Y must be filled."
778
 *
779
 * The end result is that neither of these inputs:
780
 *
781
 *	<input class="productinfo" name="partnumber">
782
 *	<input class="productinfo" name="description">
783
 *
784
 *	...will validate unless at least one of them is filled.
785
 *
786
 * partnumber:	{require_from_group: [1,".productinfo"]},
787
 * description: {require_from_group: [1,".productinfo"]}
788
 *
789
 * options[0]: number of fields that must be filled in the group
790
 * options[1]: CSS selector that defines the group of conditionally required fields
791
 */
792
$.validator.addMethod("require_from_group", function(value, element, options) {
793
	var $fields = $(options[1], element.form),
794
		$fieldsFirst = $fields.eq(0),
795
		validator = $fieldsFirst.data("valid_req_grp") ? $fieldsFirst.data("valid_req_grp") : $.extend({}, this),
796
		isValid = $fields.filter(function() {
797
			return validator.elementValue(this);
798
		}).length >= options[0];
799
 
800
	// Store the cloned validator for future validation
801
	$fieldsFirst.data("valid_req_grp", validator);
802
 
803
	// If element isn't being validated, run each require_from_group field's validation rules
804
	if (!$(element).data("being_validated")) {
805
		$fields.data("being_validated", true);
806
		$fields.each(function() {
807
			validator.element(this);
808
		});
809
		$fields.data("being_validated", false);
810
	}
811
	return isValid;
812
}, $.validator.format("Please fill at least {0} of these fields."));
813
 
814
/*
815
 * Lets you say "either at least X inputs that match selector Y must be filled,
816
 * OR they must all be skipped (left blank)."
817
 *
818
 * The end result, is that none of these inputs:
819
 *
820
 *	<input class="productinfo" name="partnumber">
821
 *	<input class="productinfo" name="description">
822
 *	<input class="productinfo" name="color">
823
 *
824
 *	...will validate unless either at least two of them are filled,
825
 *	OR none of them are.
826
 *
827
 * partnumber:	{skip_or_fill_minimum: [2,".productinfo"]},
828
 * description: {skip_or_fill_minimum: [2,".productinfo"]},
829
 * color:		{skip_or_fill_minimum: [2,".productinfo"]}
830
 *
831
 * options[0]: number of fields that must be filled in the group
832
 * options[1]: CSS selector that defines the group of conditionally required fields
833
 *
834
 */
835
$.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
836
	var $fields = $(options[1], element.form),
837
		$fieldsFirst = $fields.eq(0),
838
		validator = $fieldsFirst.data("valid_skip") ? $fieldsFirst.data("valid_skip") : $.extend({}, this),
839
		numberFilled = $fields.filter(function() {
840
			return validator.elementValue(this);
841
		}).length,
842
		isValid = numberFilled === 0 || numberFilled >= options[0];
843
 
844
	// Store the cloned validator for future validation
845
	$fieldsFirst.data("valid_skip", validator);
846
 
847
	// If element isn't being validated, run each skip_or_fill_minimum field's validation rules
848
	if (!$(element).data("being_validated")) {
849
		$fields.data("being_validated", true);
850
		$fields.each(function() {
851
			validator.element(this);
852
		});
853
		$fields.data("being_validated", false);
854
	}
855
	return isValid;
856
}, $.validator.format("Please either skip these fields or fill at least {0} of them."));
857
 
858
/* Validates US States and/or Territories by @jdforsythe
859
 * Can be case insensitive or require capitalization - default is case insensitive
860
 * Can include US Territories or not - default does not
861
 * Can include US Military postal abbreviations (AA, AE, AP) - default does not
862
 *
863
 * Note: "States" always includes DC (District of Colombia)
864
 *
865
 * Usage examples:
866
 *
867
 *  This is the default - case insensitive, no territories, no military zones
868
 *  stateInput: {
869
 *     caseSensitive: false,
870
 *     includeTerritories: false,
871
 *     includeMilitary: false
872
 *  }
873
 *
874
 *  Only allow capital letters, no territories, no military zones
875
 *  stateInput: {
876
 *     caseSensitive: false
877
 *  }
878
 *
879
 *  Case insensitive, include territories but not military zones
880
 *  stateInput: {
881
 *     includeTerritories: true
882
 *  }
883
 *
884
 *  Only allow capital letters, include territories and military zones
885
 *  stateInput: {
886
 *     caseSensitive: true,
887
 *     includeTerritories: true,
888
 *     includeMilitary: true
889
 *  }
890
 *
891
 *
892
 *
893
 */
894
 
895
$.validator.addMethod("stateUS", function(value, element, options) {
896
	var isDefault = typeof options === "undefined",
897
		caseSensitive = ( isDefault || typeof options.caseSensitive === "undefined" ) ? false : options.caseSensitive,
898
		includeTerritories = ( isDefault || typeof options.includeTerritories === "undefined" ) ? false : options.includeTerritories,
899
		includeMilitary = ( isDefault || typeof options.includeMilitary === "undefined" ) ? false : options.includeMilitary,
900
		regex;
901
 
902
	if (!includeTerritories && !includeMilitary) {
903
		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])$";
904
	} else if (includeTerritories && includeMilitary) {
905
		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])$";
906
	} else if (includeTerritories) {
907
		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])$";
908
	} else {
909
		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])$";
910
	}
911
 
912
	regex = caseSensitive ? new RegExp(regex) : new RegExp(regex, "i");
913
	return this.optional(element) || regex.test(value);
914
},
915
"Please specify a valid state");
916
 
917
// TODO check if value starts with <, otherwise don't try stripping anything
918
$.validator.addMethod("strippedminlength", function(value, element, param) {
919
	return $(value).text().length >= param;
920
}, $.validator.format("Please enter at least {0} characters"));
921
 
922
$.validator.addMethod("time", function(value, element) {
923
	return this.optional(element) || /^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test(value);
924
}, "Please enter a valid time, between 00:00 and 23:59");
925
 
926
$.validator.addMethod("time12h", function(value, element) {
927
	return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test(value);
928
}, "Please enter a valid time in 12-hour am/pm format");
929
 
930
// same as url, but TLD is optional
931
$.validator.addMethod("url2", function(value, element) {
932
	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);
933
}, $.validator.messages.url);
934
 
935
/**
936
 * Return true, if the value is a valid vehicle identification number (VIN).
937
 *
938
 * Works with all kind of text inputs.
939
 *
940
 * @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
941
 * @desc Declares a required input element whose value must be a valid vehicle identification number.
942
 *
943
 * @name $.validator.methods.vinUS
944
 * @type Boolean
945
 * @cat Plugins/Validate/Methods
946
 */
947
$.validator.addMethod("vinUS", function(v) {
948
	if (v.length !== 17) {
949
		return false;
950
	}
951
 
952
	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" ],
953
		VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
954
		FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
955
		rs = 0,
956
		i, n, d, f, cd, cdv;
957
 
958
	for (i = 0; i < 17; i++) {
959
		f = FL[i];
960
		d = v.slice(i, i + 1);
961
		if (i === 8) {
962
			cdv = d;
963
		}
964
		if (!isNaN(d)) {
965
			d *= f;
966
		} else {
967
			for (n = 0; n < LL.length; n++) {
968
				if (d.toUpperCase() === LL[n]) {
969
					d = VL[n];
970
					d *= f;
971
					if (isNaN(cdv) && n === 8) {
972
						cdv = LL[n];
973
					}
974
					break;
975
				}
976
			}
977
		}
978
		rs += d;
979
	}
980
	cd = rs % 11;
981
	if (cd === 10) {
982
		cd = "X";
983
	}
984
	if (cd === cdv) {
985
		return true;
986
	}
987
	return false;
988
}, "The specified vehicle identification number (VIN) is invalid.");
989
 
990
$.validator.addMethod("zipcodeUS", function(value, element) {
991
	return this.optional(element) || /^\d{5}(-\d{4})?$/.test(value);
992
}, "The specified US ZIP Code is invalid");
993
 
994
$.validator.addMethod("ziprange", function(value, element) {
995
	return this.optional(element) || /^90[2-5]\d\{2\}-\d{4}$/.test(value);
996
}, "Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx");
997
 
998
}));