2 * jQuery Validation Plugin v1.17.0
4 * https://jqueryvalidation.org/
6 * Copyright (c) 2017 Jörn Zaefferer
7 * Released under the MIT license
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" ) );
21 function stripHtml( value ) {
23 // Remove html tags and space chars
24 return value.replace( /<.[^<>]*?>/g, " " ).replace( / | /gi, " " )
27 .replace( /[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "" );
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." ) );
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." ) );
38 $.validator.addMethod( "rangeWords", function( value, element, params ) {
39 var valueStripped = stripHtml( value ),
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." ) );
46 // Accept a value from a file input based on a required mimetype
47 $.validator.addMethod( "accept", function( value, element, param ) {
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 ),
54 // Element is optional
55 if ( optionalValue ) {
59 if ( $( element ).attr( "type" ) === "file" ) {
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
65 .replace( /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g, "\\$&" )
67 .replace( /\/\*/g, "/.*" );
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 ];
75 // Grab the mimetype from the loaded file, verify it matches
76 if ( !file.type.match( regex ) ) {
83 // Either return true because we've validated each file, or because the
84 // browser does not support element.files and the FileList feature
86 }, $.validator.format( "Please enter a value with a valid mimetype." ) );
88 $.validator.addMethod( "alphanumeric", function( value, element ) {
89 return this.optional( element ) || /^\w+$/i.test( value );
90 }, "Letters, numbers, and underscores only please" );
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
98 $.validator.addMethod( "bankaccountNL", function( value, element ) {
99 if ( this.optional( element ) ) {
102 if ( !( /^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test( value ) ) ) {
107 var account = value.replace( / /g, "" ), // Remove spaces
109 len = account.length,
111 for ( pos = 0; pos < len; pos++ ) {
113 digit = account.substring( pos, pos + 1 );
114 sum = sum + factor * digit;
116 return sum % 11 === 0;
117 }, "Please specify a valid bank account number" );
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" );
126 * BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
128 * BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
130 * Validation is case-insensitive. Please make sure to normalize input yourself.
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)
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" );
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
148 * Spanish CIF structure:
150 * [ T ][ P ][ P ][ N ][ N ][ N ][ N ][ N ][ C ]
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].
159 * [ T ]: Kind of Organizations. Possible values:
163 * C. General partnerships
164 * D. Companies limited partnerships
165 * E. Communities of goods
166 * F. Cooperative Societies
168 * H. Communities of homeowners in horizontal property regime
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
181 * [ C ]: Control Digit. It can be a number or a letter depending on T value:
194 $.validator.addMethod( "cifES", function( value, element ) {
197 if ( this.optional( element ) ) {
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 ]
212 function isOdd( n ) {
217 if ( value.length !== 9 || !cifRegEx.test( value ) ) {
221 for ( i = 0; i < number.length; i++ ) {
222 n = parseInt( number[ i ], 10 );
227 // Odd positions are multiplied first.
230 // If the multiplication is bigger than 10 we need to adjust
231 odd_sum += n < 10 ? n : n - 9;
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();
245 // Control must be a digit
246 if ( letter.match( /[ABEH]/ ) ) {
247 return control === control_digit;
249 // Control must be a letter
250 } else if ( letter.match( /[KPQS]/ ) ) {
251 return control === control_letter;
255 return control === control_digit || control === control_letter;
257 }, "Please specify a valid CIF number." );
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.
263 $.validator.addMethod( "cpfBR", function( value ) {
265 // Removing special characters from value
266 value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );
268 // Checking value to have 11 digits only
269 if ( value.length !== 11 ) {
274 firstCN, secondCN, checkResult, i;
276 firstCN = parseInt( value.substring( 9, 10 ), 10 );
277 secondCN = parseInt( value.substring( 10, 11 ), 10 );
279 checkResult = function( sum, cn ) {
280 var result = ( sum * 10 ) % 11;
281 if ( ( result === 10 ) || ( result === 11 ) ) {
284 return ( result === cn );
287 // Checking for dump data
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"
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 );
308 // If first Check Number (CN) is valid, move to Step 2 - using second Check Number:
309 if ( checkResult( sum, firstCN ) ) {
311 for ( i = 1; i <= 10; i++ ) {
312 sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 12 - i );
314 return checkResult( sum, secondCN );
318 }, "Please specify a valid CPF number" );
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";
327 // Accept only spaces, digits and dashes
328 if ( /[^0-9 \-]+/.test( value ) ) {
337 value = value.replace( /\D/g, "" );
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 ) {
345 for ( n = value.length - 1; n >= 0; n-- ) {
346 cDigit = value.charAt( n );
347 nDigit = parseInt( cDigit, 10 );
349 if ( ( nDigit *= 2 ) > 9 ) {
358 return ( nCheck % 10 ) === 0;
359 }, "Please enter a valid credit card number." );
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)
365 $.validator.addMethod( "creditcardtypes", function( value, element, param ) {
366 if ( /[^0-9\-]+/.test( value ) ) {
370 value = value.replace( /\D/g, "" );
372 var validTypes = 0x0000;
374 if ( param.mastercard ) {
375 validTypes |= 0x0001;
378 validTypes |= 0x0002;
381 validTypes |= 0x0004;
383 if ( param.dinersclub ) {
384 validTypes |= 0x0008;
386 if ( param.enroute ) {
387 validTypes |= 0x0010;
389 if ( param.discover ) {
390 validTypes |= 0x0020;
393 validTypes |= 0x0040;
395 if ( param.unknown ) {
396 validTypes |= 0x0080;
399 validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
401 if ( validTypes & 0x0001 && /^(5[12345])/.test( value ) ) { // Mastercard
402 return value.length === 16;
404 if ( validTypes & 0x0002 && /^(4)/.test( value ) ) { // Visa
405 return value.length === 16;
407 if ( validTypes & 0x0004 && /^(3[47])/.test( value ) ) { // Amex
408 return value.length === 15;
410 if ( validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test( value ) ) { // Dinersclub
411 return value.length === 14;
413 if ( validTypes & 0x0010 && /^(2(014|149))/.test( value ) ) { // Enroute
414 return value.length === 15;
416 if ( validTypes & 0x0020 && /^(6011)/.test( value ) ) { // Discover
417 return value.length === 16;
419 if ( validTypes & 0x0040 && /^(3)/.test( value ) ) { // Jcb
420 return value.length === 16;
422 if ( validTypes & 0x0040 && /^(2131|1800)/.test( value ) ) { // Jcb
423 return value.length === 15;
425 if ( validTypes & 0x0080 ) { // Unknown
429 }, "Please enter a valid credit card number." );
432 * Validates currencies with any given symbols by @jameslouiz
433 * Symbols can be optional or required. Symbols required by default
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
440 * <input class="currencyInput" name="currencyInput">
442 * Soft symbol checking
444 * currency: ["$", false]
447 * Strict symbol checking (default)
451 * currency: ["$", true]
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 ],
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 );
471 }, "Please specify a valid currency" );
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 );
478 * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
480 * @example $.validator.methods.date("01/01/1900")
483 * @example $.validator.methods.date("01/13/1990")
486 * @example $.validator.methods.date("01.01.1900")
489 * @example <input name="pippo" class="{dateITA:true}" />
490 * @desc Declares an optional input element whose value must be a valid date.
492 * @name $.validator.methods.dateITA
494 * @cat Plugins/Validate/Methods
496 $.validator.addMethod( "dateITA", function( value, element ) {
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 ) ) {
514 return this.optional( element ) || check;
515 }, $.validator.messages.date );
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 );
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." ) );
528 * Dutch giro account numbers (not bank numbers) have max 7 digits
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" );
535 * IBAN is the international bank account number.
536 * It has a country - specific format, that is checked here too
538 * Validation is case-insensitive. Please make sure to normalize input yourself.
540 $.validator.addMethod( "iban", function( value, element ) {
542 // Some quick simple tests to prevent needless work
543 if ( this.optional( element ) ) {
547 // Remove spaces and to upper case
548 var iban = value.replace( / /g, "" ).toUpperCase(),
549 ibancheckdigits = "",
550 leadingZeroes = true,
553 countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;
555 // Check for IBAN code length.
557 // country code ISO 3166-1 - two letters,
559 // Basic Bank Account Number (BBAN) - up to 30 chars
560 var minimalIBANlength = 5;
561 if ( iban.length < minimalIBANlength ) {
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}",
571 "AZ": "[\\dA-Z]{4}\\d{20}",
573 "BH": "[A-Z]{4}[\\dA-Z]{14}",
575 "BR": "\\d{23}[A-Z][\\dA-Z]",
576 "BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
579 "CY": "\\d{8}[\\dA-Z]{16}",
582 "DO": "[A-Z]{4}\\d{20}",
586 "FR": "\\d{10}[\\dA-Z]{11}\\d{2}",
587 "GE": "[\\dA-Z]{2}\\d{16}",
589 "GI": "[A-Z]{4}[\\dA-Z]{15}",
590 "GR": "\\d{7}[\\dA-Z]{16}",
592 "GT": "[\\dA-Z]{4}[\\dA-Z]{20}",
595 "IE": "[\\dA-Z]{4}\\d{14}",
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}",
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}",
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}",
612 "NL": "[A-Z]{4}\\d{10}",
614 "PK": "[\\dA-Z]{4}\\d{16}",
615 "PS": "[\\dA-Z]{4}\\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}",
626 "CH": "\\d{5}[\\dA-Z]{12}",
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}"
634 bbanpattern = bbancountrypatterns[ countrycode ];
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
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
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;
657 if ( !leadingZeroes ) {
658 ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf( charAt );
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;
669 }, "Please specify a valid IBAN" );
671 $.validator.addMethod( "integer", function( value, element ) {
672 return this.optional( element ) || /^-?\d+$/.test( value );
673 }, "A positive or negative non-decimal number please" );
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." );
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." );
683 $.validator.addMethod( "lettersonly", function( value, element ) {
684 return this.optional( element ) || /^[a-z]+$/i.test( value );
685 }, "Letters only please" );
687 $.validator.addMethod( "letterswithbasicpunc", function( value, element ) {
688 return this.optional( element ) || /^[a-z\-.,()'"\s]+$/i.test( value );
689 }, "Letters or punctuation only please" );
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" );
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
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" );
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." );
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.
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.
721 $.validator.addMethod( "nieES", function( value, element ) {
724 if ( this.optional( element ) ) {
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(),
733 value = value.toString().toUpperCase();
736 if ( value.length > 10 || value.length < 9 || !nieRegEx.test( value ) ) {
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" );
747 number = value.length === 9 ? value.substr( 0, 8 ) : value.substr( 0, 9 );
749 return validChars.charAt( parseInt( number, 10 ) % 23 ) === letter;
751 }, "Please specify a valid NIE number." );
754 * The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
756 $.validator.addMethod( "nifES", function( value, element ) {
759 if ( this.optional( element ) ) {
763 value = value.toUpperCase();
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}$)" ) ) {
771 if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {
772 return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );
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 ) );
782 }, "Please specify a valid NIF number." );
785 * Numer identyfikacji podatkowej ( NIP ) is the way tax identification used in Poland for companies
787 $.validator.addMethod( "nipPL", function( value ) {
790 value = value.replace( /[^0-9]/g, "" );
792 if ( value.length !== 10 ) {
796 var arrSteps = [ 6, 5, 7, 2, 3, 4, 5, 6, 7 ];
798 for ( var i = 0; i < 9; i++ ) {
799 intSum += arrSteps[ i ] * value[ i ];
801 var int2 = intSum % 11;
802 var intControlNr = ( int2 === 10 ) ? 0 : int2;
804 return ( intControlNr === parseInt( value[ 9 ], 10 ) );
805 }, "Please specify a valid NIP number." );
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." );
811 $.validator.addMethod( "nowhitespace", function( value, element ) {
812 return this.optional( element ) || /^\S+$/i.test( value );
813 }, "No white space please" );
816 * Return true if the field value matches the given format RegExp
818 * @example $.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)
821 * @example $.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)
824 * @name $.validator.methods.pattern
826 * @cat Plugins/Validate/Methods
828 $.validator.addMethod( "pattern", function( value, element, param ) {
829 if ( this.optional( element ) ) {
832 if ( typeof param === "string" ) {
833 param = new RegExp( "^(?:" + param + ")$" );
835 return param.test( value );
836 }, "Invalid format." );
839 * Dutch phone numbers have 10 digits (or 11 and start with +31).
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." );
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
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" );
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
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" );
876 * Matches US phone number format
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
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" );
898 * Valida CEPs do brasileiros:
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." );
910 * Matches a valid Canadian Postal Code
912 * @example jQuery.validator.methods.postalCodeCA( "H0H 0H0", element )
915 * @example jQuery.validator.methods.postalCodeCA( "H0H0H0", element )
918 * @name jQuery.validator.methods.postalCodeCA
920 * @cat Plugins/Validate/Methods
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" );
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" );
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" );
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" );
941 * Lets you say "at least X inputs that match selector Y must be filled."
943 * The end result is that neither of these inputs:
945 * <input class="productinfo" name="partnumber">
946 * <input class="productinfo" name="description">
948 * ...will validate unless at least one of them is filled.
950 * partnumber: {require_from_group: [1,".productinfo"]},
951 * description: {require_from_group: [1,".productinfo"]}
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
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 ];
964 // Store the cloned validator for future validation
965 $fieldsFirst.data( "valid_req_grp", validator );
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 );
973 $fields.data( "being_validated", false );
976 }, $.validator.format( "Please fill at least {0} of these fields." ) );
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)."
982 * The end result, is that none of these inputs:
984 * <input class="productinfo" name="partnumber">
985 * <input class="productinfo" name="description">
986 * <input class="productinfo" name="color">
988 * ...will validate unless either at least two of them are filled,
989 * OR none of them are.
991 * partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
992 * description: {skip_or_fill_minimum: [2,".productinfo"]},
993 * color: {skip_or_fill_minimum: [2,".productinfo"]}
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
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 );
1006 isValid = numberFilled === 0 || numberFilled >= options[ 0 ];
1008 // Store the cloned validator for future validation
1009 $fieldsFirst.data( "valid_skip", validator );
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 );
1017 $fields.data( "being_validated", false );
1020 }, $.validator.format( "Please either skip these fields or fill at least {0} of them." ) );
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
1027 * Note: "States" always includes DC (District of Colombia)
1031 * This is the default - case insensitive, no territories, no military zones
1033 * caseSensitive: false,
1034 * includeTerritories: false,
1035 * includeMilitary: false
1038 * Only allow capital letters, no territories, no military zones
1040 * caseSensitive: false
1043 * Case insensitive, include territories but not military zones
1045 * includeTerritories: true
1048 * Only allow capital letters, include territories and military zones
1050 * caseSensitive: true,
1051 * includeTerritories: true,
1052 * includeMilitary: true
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,
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])$";
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])$";
1073 regex = caseSensitive ? new RegExp( regex ) : new RegExp( regex, "i" );
1074 return this.optional( element ) || regex.test( value );
1075 }, "Please specify a valid state" );
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" ) );
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" );
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" );
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 );
1096 * Return true, if the value is a valid vehicle identification number (VIN).
1098 * Works with all kind of text inputs.
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.
1103 * @name $.validator.methods.vinUS
1105 * @cat Plugins/Validate/Methods
1107 $.validator.addMethod( "vinUS", function( v ) {
1108 if ( v.length !== 17 ) {
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 ],
1116 i, n, d, f, cd, cdv;
1118 for ( i = 0; i < 17; i++ ) {
1120 d = v.slice( i, i + 1 );
1124 if ( !isNaN( d ) ) {
1127 for ( n = 0; n < LL.length; n++ ) {
1128 if ( d.toUpperCase() === LL[ n ] ) {
1131 if ( isNaN( cdv ) && n === 8 ) {
1148 }, "The specified vehicle identification number (VIN) is invalid." );
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" );
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" );