source: Application/ocrent/wwwroot/lib/jquery-validation/dist/additional-methods.js@ f5f7c24

Last change on this file since f5f7c24 was f5f7c24, checked in by 192011 <mk.snicker@…>, 17 months ago

Initial commit

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