GPQAPP
1512 строк · 50.8 Кб
1/*!
2* jQuery Validation Plugin v1.19.3
3*
4* https://jqueryvalidation.org/
5*
6* Copyright (c) 2021 Jörn Zaefferer
7* Released under the MIT license
8*/
9(function( factory ) {10if ( typeof define === "function" && define.amd ) {11define( ["jquery", "./jquery.validate"], factory );12} else if (typeof module === "object" && module.exports) {13module.exports = factory( require( "jquery" ) );14} else {15factory( jQuery );16}17}(function( $ ) {18
19( function() {20
21function stripHtml( value ) {22
23// Remove html tags and space chars24return value.replace( /<.[^<>]*?>/g, " " ).replace( / | /gi, " " )25
26// Remove punctuation27.replace( /[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "" );28}29
30$.validator.addMethod( "maxWords", function( value, element, params ) {31return 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 ) {35return 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 ) {39var valueStripped = stripHtml( value ),40regex = /\b\w+\b/g;41return 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/**
47* This is used in the United States to process payments, deposits,
48* or transfers using the Automated Clearing House (ACH) or Fedwire
49* systems. A very common use case would be to validate a form for
50* an ACH bill payment.
51*/
52$.validator.addMethod( "abaRoutingNumber", function( value ) {53var checksum = 0;54var tokens = value.split( "" );55var length = tokens.length;56
57// Length Check58if ( length !== 9 ) {59return false;60}61
62// Calc the checksum63// https://en.wikipedia.org/wiki/ABA_routing_transit_number64for ( var i = 0; i < length; i += 3 ) {65checksum += parseInt( tokens[ i ], 10 ) * 3 +66parseInt( tokens[ i + 1 ], 10 ) * 7 +67parseInt( tokens[ i + 2 ], 10 );68}69
70// If not zero and divisible by 10 then valid71if ( checksum !== 0 && checksum % 10 === 0 ) {72return true;73}74
75return false;76}, "Please enter a valid routing number." );77
78// Accept a value from a file input based on a required mimetype
79$.validator.addMethod( "accept", function( value, element, param ) {80
81// Split mime on commas in case we have multiple types we can accept82var typeParam = typeof param === "string" ? param.replace( /\s/g, "" ) : "image/*",83optionalValue = this.optional( element ),84i, file, regex;85
86// Element is optional87if ( optionalValue ) {88return optionalValue;89}90
91if ( $( element ).attr( "type" ) === "file" ) {92
93// Escape string to be used in the regex94// see: https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex95// Escape also "/*" as "/.*" as a wildcard96typeParam = typeParam97.replace( /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g, "\\$&" )98.replace( /,/g, "|" )99.replace( /\/\*/g, "/.*" );100
101// Check if the element has a FileList before checking each file102if ( element.files && element.files.length ) {103regex = new RegExp( ".?(" + typeParam + ")$", "i" );104for ( i = 0; i < element.files.length; i++ ) {105file = element.files[ i ];106
107// Grab the mimetype from the loaded file, verify it matches108if ( !file.type.match( regex ) ) {109return false;110}111}112}113}114
115// Either return true because we've validated each file, or because the116// browser does not support element.files and the FileList feature117return true;118}, $.validator.format( "Please enter a value with a valid mimetype." ) );119
120$.validator.addMethod( "alphanumeric", function( value, element ) {121return this.optional( element ) || /^\w+$/i.test( value );122}, "Letters, numbers, and underscores only please" );123
124/*
125* Dutch bank account numbers (not 'giro' numbers) have 9 digits
126* and pass the '11 check'.
127* We accept the notation with spaces, as that is common.
128* acceptable: 123456789 or 12 34 56 789
129*/
130$.validator.addMethod( "bankaccountNL", function( value, element ) {131if ( this.optional( element ) ) {132return true;133}134if ( !( /^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test( value ) ) ) {135return false;136}137
138// Now '11 check'139var account = value.replace( / /g, "" ), // Remove spaces140sum = 0,141len = account.length,142pos, factor, digit;143for ( pos = 0; pos < len; pos++ ) {144factor = len - pos;145digit = account.substring( pos, pos + 1 );146sum = sum + factor * digit;147}148return sum % 11 === 0;149}, "Please specify a valid bank account number" );150
151$.validator.addMethod( "bankorgiroaccountNL", function( value, element ) {152return this.optional( element ) ||153( $.validator.methods.bankaccountNL.call( this, value, element ) ) ||154( $.validator.methods.giroaccountNL.call( this, value, element ) );155}, "Please specify a valid bank or giro account number" );156
157/**
158* BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
159*
160* BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
161*
162* Validation is case-insensitive. Please make sure to normalize input yourself.
163*
164* BIC definition in detail:
165* - First 4 characters - bank code (only letters)
166* - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
167* - Next 2 characters - location code (letters and digits)
168* a. shall not start with '0' or '1'
169* 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)
170* - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)
171*/
172$.validator.addMethod( "bic", function( value, element ) {173return 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() );174}, "Please specify a valid BIC code" );175
176/*
177* Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
178* Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
179*
180* Spanish CIF structure:
181*
182* [ T ][ P ][ P ][ N ][ N ][ N ][ N ][ N ][ C ]
183*
184* Where:
185*
186* T: 1 character. Kind of Organization Letter: [ABCDEFGHJKLMNPQRSUVW]
187* P: 2 characters. Province.
188* N: 5 characters. Secuencial Number within the province.
189* C: 1 character. Control Digit: [0-9A-J].
190*
191* [ T ]: Kind of Organizations. Possible values:
192*
193* A. Corporations
194* B. LLCs
195* C. General partnerships
196* D. Companies limited partnerships
197* E. Communities of goods
198* F. Cooperative Societies
199* G. Associations
200* H. Communities of homeowners in horizontal property regime
201* J. Civil Societies
202* K. Old format
203* L. Old format
204* M. Old format
205* N. Nonresident entities
206* P. Local authorities
207* Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions
208* R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)
209* S. Organs of State Administration and regions
210* V. Agrarian Transformation
211* W. Permanent establishments of non-resident in Spain
212*
213* [ C ]: Control Digit. It can be a number or a letter depending on T value:
214* [ T ] --> [ C ]
215* ------ ----------
216* A Number
217* B Number
218* E Number
219* H Number
220* K Letter
221* P Letter
222* Q Letter
223* S Letter
224*
225*/
226$.validator.addMethod( "cifES", function( value, element ) {227"use strict";228
229if ( this.optional( element ) ) {230return true;231}232
233var cifRegEx = new RegExp( /^([ABCDEFGHJKLMNPQRSUVW])(\d{7})([0-9A-J])$/gi );234var letter = value.substring( 0, 1 ), // [ T ]235number = value.substring( 1, 8 ), // [ P ][ P ][ N ][ N ][ N ][ N ][ N ]236control = value.substring( 8, 9 ), // [ C ]237all_sum = 0,238even_sum = 0,239odd_sum = 0,240i, n,241control_digit,242control_letter;243
244function isOdd( n ) {245return n % 2 === 0;246}247
248// Quick format test249if ( value.length !== 9 || !cifRegEx.test( value ) ) {250return false;251}252
253for ( i = 0; i < number.length; i++ ) {254n = parseInt( number[ i ], 10 );255
256// Odd positions257if ( isOdd( i ) ) {258
259// Odd positions are multiplied first.260n *= 2;261
262// If the multiplication is bigger than 10 we need to adjust263odd_sum += n < 10 ? n : n - 9;264
265// Even positions266// Just sum them267} else {268even_sum += n;269}270}271
272all_sum = even_sum + odd_sum;273control_digit = ( 10 - ( all_sum ).toString().substr( -1 ) ).toString();274control_digit = parseInt( control_digit, 10 ) > 9 ? "0" : control_digit;275control_letter = "JABCDEFGHI".substr( control_digit, 1 ).toString();276
277// Control must be a digit278if ( letter.match( /[ABEH]/ ) ) {279return control === control_digit;280
281// Control must be a letter282} else if ( letter.match( /[KPQS]/ ) ) {283return control === control_letter;284}285
286// Can be either287return control === control_digit || control === control_letter;288
289}, "Please specify a valid CIF number." );290
291/*
292* Brazillian CNH number (Carteira Nacional de Habilitacao) is the License Driver number.
293* CNH numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.
294*/
295$.validator.addMethod( "cnhBR", function( value ) {296
297// Removing special characters from value298value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );299
300// Checking value to have 11 digits only301if ( value.length !== 11 ) {302return false;303}304
305var sum = 0, dsc = 0, firstChar,306firstCN, secondCN, i, j, v;307
308firstChar = value.charAt( 0 );309
310if ( new Array( 12 ).join( firstChar ) === value ) {311return false;312}313
314// Step 1 - using first Check Number:315for ( i = 0, j = 9, v = 0; i < 9; ++i, --j ) {316sum += +( value.charAt( i ) * j );317}318
319firstCN = sum % 11;320if ( firstCN >= 10 ) {321firstCN = 0;322dsc = 2;323}324
325sum = 0;326for ( i = 0, j = 1, v = 0; i < 9; ++i, ++j ) {327sum += +( value.charAt( i ) * j );328}329
330secondCN = sum % 11;331if ( secondCN >= 10 ) {332secondCN = 0;333} else {334secondCN = secondCN - dsc;335}336
337return ( String( firstCN ).concat( secondCN ) === value.substr( -2 ) );338
339}, "Please specify a valid CNH number" );340
341/*
342* Brazillian value number (Cadastrado de Pessoas Juridica).
343* value numbers have 14 digits in total: 12 numbers followed by 2 check numbers that are being used for validation.
344*/
345$.validator.addMethod( "cnpjBR", function( value, element ) {346"use strict";347
348if ( this.optional( element ) ) {349return true;350}351
352// Removing no number353value = value.replace( /[^\d]+/g, "" );354
355// Checking value to have 14 digits only356if ( value.length !== 14 ) {357return false;358}359
360// Elimina values invalidos conhecidos361if ( value === "00000000000000" ||362value === "11111111111111" ||363value === "22222222222222" ||364value === "33333333333333" ||365value === "44444444444444" ||366value === "55555555555555" ||367value === "66666666666666" ||368value === "77777777777777" ||369value === "88888888888888" ||370value === "99999999999999" ) {371return false;372}373
374// Valida DVs375var tamanho = ( value.length - 2 );376var numeros = value.substring( 0, tamanho );377var digitos = value.substring( tamanho );378var soma = 0;379var pos = tamanho - 7;380
381for ( var i = tamanho; i >= 1; i-- ) {382soma += numeros.charAt( tamanho - i ) * pos--;383if ( pos < 2 ) {384pos = 9;385}386}387
388var resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;389
390if ( resultado !== parseInt( digitos.charAt( 0 ), 10 ) ) {391return false;392}393
394tamanho = tamanho + 1;395numeros = value.substring( 0, tamanho );396soma = 0;397pos = tamanho - 7;398
399for ( var il = tamanho; il >= 1; il-- ) {400soma += numeros.charAt( tamanho - il ) * pos--;401if ( pos < 2 ) {402pos = 9;403}404}405
406resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;407
408if ( resultado !== parseInt( digitos.charAt( 1 ), 10 ) ) {409return false;410}411
412return true;413
414}, "Please specify a CNPJ value number" );415
416/*
417* Brazillian CPF number (Cadastrado de Pessoas Físicas) is the equivalent of a Brazilian tax registration number.
418* CPF numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.
419*/
420$.validator.addMethod( "cpfBR", function( value, element ) {421"use strict";422
423if ( this.optional( element ) ) {424return true;425}426
427// Removing special characters from value428value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );429
430// Checking value to have 11 digits only431if ( value.length !== 11 ) {432return false;433}434
435var sum = 0,436firstCN, secondCN, checkResult, i;437
438firstCN = parseInt( value.substring( 9, 10 ), 10 );439secondCN = parseInt( value.substring( 10, 11 ), 10 );440
441checkResult = function( sum, cn ) {442var result = ( sum * 10 ) % 11;443if ( ( result === 10 ) || ( result === 11 ) ) {444result = 0;445}446return ( result === cn );447};448
449// Checking for dump data450if ( value === "" ||451value === "00000000000" ||452value === "11111111111" ||453value === "22222222222" ||454value === "33333333333" ||455value === "44444444444" ||456value === "55555555555" ||457value === "66666666666" ||458value === "77777777777" ||459value === "88888888888" ||460value === "99999999999"461) {462return false;463}464
465// Step 1 - using first Check Number:466for ( i = 1; i <= 9; i++ ) {467sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 11 - i );468}469
470// If first Check Number (CN) is valid, move to Step 2 - using second Check Number:471if ( checkResult( sum, firstCN ) ) {472sum = 0;473for ( i = 1; i <= 10; i++ ) {474sum = sum + parseInt( value.substring( i - 1, i ), 10 ) * ( 12 - i );475}476return checkResult( sum, secondCN );477}478return false;479
480}, "Please specify a valid CPF number" );481
482// https://jqueryvalidation.org/creditcard-method/
483// based on https://en.wikipedia.org/wiki/Luhn_algorithm
484$.validator.addMethod( "creditcard", function( value, element ) {485if ( this.optional( element ) ) {486return "dependency-mismatch";487}488
489// Accept only spaces, digits and dashes490if ( /[^0-9 \-]+/.test( value ) ) {491return false;492}493
494var nCheck = 0,495nDigit = 0,496bEven = false,497n, cDigit;498
499value = value.replace( /\D/g, "" );500
501// Basing min and max length on502// https://dev.ean.com/general-info/valid-card-types/503if ( value.length < 13 || value.length > 19 ) {504return false;505}506
507for ( n = value.length - 1; n >= 0; n-- ) {508cDigit = value.charAt( n );509nDigit = parseInt( cDigit, 10 );510if ( bEven ) {511if ( ( nDigit *= 2 ) > 9 ) {512nDigit -= 9;513}514}515
516nCheck += nDigit;517bEven = !bEven;518}519
520return ( nCheck % 10 ) === 0;521}, "Please enter a valid credit card number." );522
523/* NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
524* Redistributed under the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
525* Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
526*/
527$.validator.addMethod( "creditcardtypes", function( value, element, param ) {528if ( /[^0-9\-]+/.test( value ) ) {529return false;530}531
532value = value.replace( /\D/g, "" );533
534var validTypes = 0x0000;535
536if ( param.mastercard ) {537validTypes |= 0x0001;538}539if ( param.visa ) {540validTypes |= 0x0002;541}542if ( param.amex ) {543validTypes |= 0x0004;544}545if ( param.dinersclub ) {546validTypes |= 0x0008;547}548if ( param.enroute ) {549validTypes |= 0x0010;550}551if ( param.discover ) {552validTypes |= 0x0020;553}554if ( param.jcb ) {555validTypes |= 0x0040;556}557if ( param.unknown ) {558validTypes |= 0x0080;559}560if ( param.all ) {561validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;562}563if ( validTypes & 0x0001 && ( /^(5[12345])/.test( value ) || /^(2[234567])/.test( value ) ) ) { // Mastercard564return value.length === 16;565}566if ( validTypes & 0x0002 && /^(4)/.test( value ) ) { // Visa567return value.length === 16;568}569if ( validTypes & 0x0004 && /^(3[47])/.test( value ) ) { // Amex570return value.length === 15;571}572if ( validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test( value ) ) { // Dinersclub573return value.length === 14;574}575if ( validTypes & 0x0010 && /^(2(014|149))/.test( value ) ) { // Enroute576return value.length === 15;577}578if ( validTypes & 0x0020 && /^(6011)/.test( value ) ) { // Discover579return value.length === 16;580}581if ( validTypes & 0x0040 && /^(3)/.test( value ) ) { // Jcb582return value.length === 16;583}584if ( validTypes & 0x0040 && /^(2131|1800)/.test( value ) ) { // Jcb585return value.length === 15;586}587if ( validTypes & 0x0080 ) { // Unknown588return true;589}590return false;591}, "Please enter a valid credit card number." );592
593/**
594* Validates currencies with any given symbols by @jameslouiz
595* Symbols can be optional or required. Symbols required by default
596*
597* Usage examples:
598* currency: ["£", false] - Use false for soft currency validation
599* currency: ["$", false]
600* currency: ["RM", false] - also works with text based symbols such as "RM" - Malaysia Ringgit etc
601*
602* <input class="currencyInput" name="currencyInput">
603*
604* Soft symbol checking
605* currencyInput: {
606* currency: ["$", false]
607* }
608*
609* Strict symbol checking (default)
610* currencyInput: {
611* currency: "$"
612* //OR
613* currency: ["$", true]
614* }
615*
616* Multiple Symbols
617* currencyInput: {
618* currency: "$,£,¢"
619* }
620*/
621$.validator.addMethod( "currency", function( value, element, param ) {622var isParamString = typeof param === "string",623symbol = isParamString ? param : param[ 0 ],624soft = isParamString ? true : param[ 1 ],625regex;626
627symbol = symbol.replace( /,/g, "" );628symbol = soft ? symbol + "]" : symbol + "]?";629regex = "^[" + 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})?)$";630regex = new RegExp( regex );631return this.optional( element ) || regex.test( value );632
633}, "Please specify a valid currency" );634
635$.validator.addMethod( "dateFA", function( value, element ) {636return 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 );637}, $.validator.messages.date );638
639/**
640* Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
641*
642* @example $.validator.methods.date("01/01/1900")
643* @result true
644*
645* @example $.validator.methods.date("01/13/1990")
646* @result false
647*
648* @example $.validator.methods.date("01.01.1900")
649* @result false
650*
651* @example <input name="pippo" class="{dateITA:true}" />
652* @desc Declares an optional input element whose value must be a valid date.
653*
654* @name $.validator.methods.dateITA
655* @type Boolean
656* @cat Plugins/Validate/Methods
657*/
658$.validator.addMethod( "dateITA", function( value, element ) {659var check = false,660re = /^\d{1,2}\/\d{1,2}\/\d{4}$/,661adata, gg, mm, aaaa, xdata;662if ( re.test( value ) ) {663adata = value.split( "/" );664gg = parseInt( adata[ 0 ], 10 );665mm = parseInt( adata[ 1 ], 10 );666aaaa = parseInt( adata[ 2 ], 10 );667xdata = new Date( Date.UTC( aaaa, mm - 1, gg, 12, 0, 0, 0 ) );668if ( ( xdata.getUTCFullYear() === aaaa ) && ( xdata.getUTCMonth() === mm - 1 ) && ( xdata.getUTCDate() === gg ) ) {669check = true;670} else {671check = false;672}673} else {674check = false;675}676return this.optional( element ) || check;677}, $.validator.messages.date );678
679$.validator.addMethod( "dateNL", function( value, element ) {680return this.optional( element ) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test( value );681}, $.validator.messages.date );682
683// Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept
684$.validator.addMethod( "extension", function( value, element, param ) {685param = typeof param === "string" ? param.replace( /,/g, "|" ) : "png|jpe?g|gif";686return this.optional( element ) || value.match( new RegExp( "\\.(" + param + ")$", "i" ) );687}, $.validator.format( "Please enter a value with a valid extension." ) );688
689/**
690* Dutch giro account numbers (not bank numbers) have max 7 digits
691*/
692$.validator.addMethod( "giroaccountNL", function( value, element ) {693return this.optional( element ) || /^[0-9]{1,7}$/.test( value );694}, "Please specify a valid giro account number" );695
696$.validator.addMethod( "greaterThan", function( value, element, param ) {697var target = $( param );698
699if ( this.settings.onfocusout && target.not( ".validate-greaterThan-blur" ).length ) {700target.addClass( "validate-greaterThan-blur" ).on( "blur.validate-greaterThan", function() {701$( element ).valid();702} );703}704
705return value > target.val();706}, "Please enter a greater value." );707
708$.validator.addMethod( "greaterThanEqual", function( value, element, param ) {709var target = $( param );710
711if ( this.settings.onfocusout && target.not( ".validate-greaterThanEqual-blur" ).length ) {712target.addClass( "validate-greaterThanEqual-blur" ).on( "blur.validate-greaterThanEqual", function() {713$( element ).valid();714} );715}716
717return value >= target.val();718}, "Please enter a greater value." );719
720/**
721* IBAN is the international bank account number.
722* It has a country - specific format, that is checked here too
723*
724* Validation is case-insensitive. Please make sure to normalize input yourself.
725*/
726$.validator.addMethod( "iban", function( value, element ) {727
728// Some quick simple tests to prevent needless work729if ( this.optional( element ) ) {730return true;731}732
733// Remove spaces and to upper case734var iban = value.replace( / /g, "" ).toUpperCase(),735ibancheckdigits = "",736leadingZeroes = true,737cRest = "",738cOperator = "",739countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;740
741// Check for IBAN code length.742// It contains:743// country code ISO 3166-1 - two letters,744// two check digits,745// Basic Bank Account Number (BBAN) - up to 30 chars746var minimalIBANlength = 5;747if ( iban.length < minimalIBANlength ) {748return false;749}750
751// Check the country code and find the country specific format752countrycode = iban.substring( 0, 2 );753bbancountrypatterns = {754"AL": "\\d{8}[\\dA-Z]{16}",755"AD": "\\d{8}[\\dA-Z]{12}",756"AT": "\\d{16}",757"AZ": "[\\dA-Z]{4}\\d{20}",758"BE": "\\d{12}",759"BH": "[A-Z]{4}[\\dA-Z]{14}",760"BA": "\\d{16}",761"BR": "\\d{23}[A-Z][\\dA-Z]",762"BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",763"CR": "\\d{17}",764"HR": "\\d{17}",765"CY": "\\d{8}[\\dA-Z]{16}",766"CZ": "\\d{20}",767"DK": "\\d{14}",768"DO": "[A-Z]{4}\\d{20}",769"EE": "\\d{16}",770"FO": "\\d{14}",771"FI": "\\d{14}",772"FR": "\\d{10}[\\dA-Z]{11}\\d{2}",773"GE": "[\\dA-Z]{2}\\d{16}",774"DE": "\\d{18}",775"GI": "[A-Z]{4}[\\dA-Z]{15}",776"GR": "\\d{7}[\\dA-Z]{16}",777"GL": "\\d{14}",778"GT": "[\\dA-Z]{4}[\\dA-Z]{20}",779"HU": "\\d{24}",780"IS": "\\d{22}",781"IE": "[\\dA-Z]{4}\\d{14}",782"IL": "\\d{19}",783"IT": "[A-Z]\\d{10}[\\dA-Z]{12}",784"KZ": "\\d{3}[\\dA-Z]{13}",785"KW": "[A-Z]{4}[\\dA-Z]{22}",786"LV": "[A-Z]{4}[\\dA-Z]{13}",787"LB": "\\d{4}[\\dA-Z]{20}",788"LI": "\\d{5}[\\dA-Z]{12}",789"LT": "\\d{16}",790"LU": "\\d{3}[\\dA-Z]{13}",791"MK": "\\d{3}[\\dA-Z]{10}\\d{2}",792"MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",793"MR": "\\d{23}",794"MU": "[A-Z]{4}\\d{19}[A-Z]{3}",795"MC": "\\d{10}[\\dA-Z]{11}\\d{2}",796"MD": "[\\dA-Z]{2}\\d{18}",797"ME": "\\d{18}",798"NL": "[A-Z]{4}\\d{10}",799"NO": "\\d{11}",800"PK": "[\\dA-Z]{4}\\d{16}",801"PS": "[\\dA-Z]{4}\\d{21}",802"PL": "\\d{24}",803"PT": "\\d{21}",804"RO": "[A-Z]{4}[\\dA-Z]{16}",805"SM": "[A-Z]\\d{10}[\\dA-Z]{12}",806"SA": "\\d{2}[\\dA-Z]{18}",807"RS": "\\d{18}",808"SK": "\\d{20}",809"SI": "\\d{15}",810"ES": "\\d{20}",811"SE": "\\d{20}",812"CH": "\\d{5}[\\dA-Z]{12}",813"TN": "\\d{20}",814"TR": "\\d{5}[\\dA-Z]{17}",815"AE": "\\d{3}\\d{16}",816"GB": "[A-Z]{4}\\d{14}",817"VG": "[\\dA-Z]{4}\\d{16}"818};819
820bbanpattern = bbancountrypatterns[ countrycode ];821
822// As new countries will start using IBAN in the823// future, we only check if the countrycode is known.824// This prevents false negatives, while almost all825// false positives introduced by this, will be caught826// by the checksum validation below anyway.827// Strict checking should return FALSE for unknown828// countries.829if ( typeof bbanpattern !== "undefined" ) {830ibanregexp = new RegExp( "^[A-Z]{2}\\d{2}" + bbanpattern + "$", "" );831if ( !( ibanregexp.test( iban ) ) ) {832return false; // Invalid country specific format833}834}835
836// Now check the checksum, first convert to digits837ibancheck = iban.substring( 4, iban.length ) + iban.substring( 0, 4 );838for ( i = 0; i < ibancheck.length; i++ ) {839charAt = ibancheck.charAt( i );840if ( charAt !== "0" ) {841leadingZeroes = false;842}843if ( !leadingZeroes ) {844ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf( charAt );845}846}847
848// Calculate the result of: ibancheckdigits % 97849for ( p = 0; p < ibancheckdigits.length; p++ ) {850cChar = ibancheckdigits.charAt( p );851cOperator = "" + cRest + "" + cChar;852cRest = cOperator % 97;853}854return cRest === 1;855}, "Please specify a valid IBAN" );856
857$.validator.addMethod( "integer", function( value, element ) {858return this.optional( element ) || /^-?\d+$/.test( value );859}, "A positive or negative non-decimal number please" );860
861$.validator.addMethod( "ipv4", function( value, element ) {862return 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 );863}, "Please enter a valid IP v4 address." );864
865$.validator.addMethod( "ipv6", function( value, element ) {866return 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 );867}, "Please enter a valid IP v6 address." );868
869$.validator.addMethod( "lessThan", function( value, element, param ) {870var target = $( param );871
872if ( this.settings.onfocusout && target.not( ".validate-lessThan-blur" ).length ) {873target.addClass( "validate-lessThan-blur" ).on( "blur.validate-lessThan", function() {874$( element ).valid();875} );876}877
878return value < target.val();879}, "Please enter a lesser value." );880
881$.validator.addMethod( "lessThanEqual", function( value, element, param ) {882var target = $( param );883
884if ( this.settings.onfocusout && target.not( ".validate-lessThanEqual-blur" ).length ) {885target.addClass( "validate-lessThanEqual-blur" ).on( "blur.validate-lessThanEqual", function() {886$( element ).valid();887} );888}889
890return value <= target.val();891}, "Please enter a lesser value." );892
893$.validator.addMethod( "lettersonly", function( value, element ) {894return this.optional( element ) || /^[a-z]+$/i.test( value );895}, "Letters only please" );896
897$.validator.addMethod( "letterswithbasicpunc", function( value, element ) {898return this.optional( element ) || /^[a-z\-.,()'"\s]+$/i.test( value );899}, "Letters or punctuation only please" );900
901// Limit the number of files in a FileList.
902$.validator.addMethod( "maxfiles", function( value, element, param ) {903if ( this.optional( element ) ) {904return true;905}906
907if ( $( element ).attr( "type" ) === "file" ) {908if ( element.files && element.files.length > param ) {909return false;910}911}912
913return true;914}, $.validator.format( "Please select no more than {0} files." ) );915
916// Limit the size of each individual file in a FileList.
917$.validator.addMethod( "maxsize", function( value, element, param ) {918if ( this.optional( element ) ) {919return true;920}921
922if ( $( element ).attr( "type" ) === "file" ) {923if ( element.files && element.files.length ) {924for ( var i = 0; i < element.files.length; i++ ) {925if ( element.files[ i ].size > param ) {926return false;927}928}929}930}931
932return true;933}, $.validator.format( "File size must not exceed {0} bytes each." ) );934
935// Limit the size of all files in a FileList.
936$.validator.addMethod( "maxsizetotal", function( value, element, param ) {937if ( this.optional( element ) ) {938return true;939}940
941if ( $( element ).attr( "type" ) === "file" ) {942if ( element.files && element.files.length ) {943var totalSize = 0;944
945for ( var i = 0; i < element.files.length; i++ ) {946totalSize += element.files[ i ].size;947if ( totalSize > param ) {948return false;949}950}951}952}953
954return true;955}, $.validator.format( "Total size of all files must not exceed {0} bytes." ) );956
957
958$.validator.addMethod( "mobileNL", function( value, element ) {959return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test( value );960}, "Please specify a valid mobile number" );961
962$.validator.addMethod( "mobileRU", function( phone_number, element ) {963var ruPhone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );964return this.optional( element ) || ruPhone_number.length > 9 && /^((\+7|7|8)+([0-9]){10})$/.test( ruPhone_number );965}, "Please specify a valid mobile number" );966
967/* For UK phone functions, do the following server side processing:
968* Compare original input with this RegEx pattern:
969* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
970* Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
971* Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
972* A number of very detailed GB telephone number RegEx patterns can also be found at:
973* http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
974*/
975$.validator.addMethod( "mobileUK", function( phone_number, element ) {976phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );977return this.optional( element ) || phone_number.length > 9 &&978phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/ );979}, "Please specify a valid mobile number" );980
981$.validator.addMethod( "netmask", function( value, element ) {982return this.optional( element ) || /^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)/i.test( value );983}, "Please enter a valid netmask." );984
985/*
986* The NIE (Número de Identificación de Extranjero) is a Spanish tax identification number assigned by the Spanish
987* authorities to any foreigner.
988*
989* The NIE is the equivalent of a Spaniards Número de Identificación Fiscal (NIF) which serves as a fiscal
990* identification number. The CIF number (Certificado de Identificación Fiscal) is equivalent to the NIF, but applies to
991* companies rather than individuals. The NIE consists of an 'X' or 'Y' followed by 7 or 8 digits then another letter.
992*/
993$.validator.addMethod( "nieES", function( value, element ) {994"use strict";995
996if ( this.optional( element ) ) {997return true;998}999
1000var nieRegEx = new RegExp( /^[MXYZ]{1}[0-9]{7,8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/gi );1001var validChars = "TRWAGMYFPDXBNJZSQVHLCKET",1002letter = value.substr( value.length - 1 ).toUpperCase(),1003number;1004
1005value = value.toString().toUpperCase();1006
1007// Quick format test1008if ( value.length > 10 || value.length < 9 || !nieRegEx.test( value ) ) {1009return false;1010}1011
1012// X means same number1013// Y means number + 100000001014// Z means number + 200000001015value = value.replace( /^[X]/, "0" )1016.replace( /^[Y]/, "1" )1017.replace( /^[Z]/, "2" );1018
1019number = value.length === 9 ? value.substr( 0, 8 ) : value.substr( 0, 9 );1020
1021return validChars.charAt( parseInt( number, 10 ) % 23 ) === letter;1022
1023}, "Please specify a valid NIE number." );1024
1025/*
1026* The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
1027*/
1028$.validator.addMethod( "nifES", function( value, element ) {1029"use strict";1030
1031if ( this.optional( element ) ) {1032return true;1033}1034
1035value = value.toUpperCase();1036
1037// Basic format test1038if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {1039return false;1040}1041
1042// Test NIF1043if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {1044return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );1045}1046
1047// Test specials NIF (starts with K, L or M)1048if ( /^[KLM]{1}/.test( value ) ) {1049return ( value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 1 ) % 23 ) );1050}1051
1052return false;1053
1054}, "Please specify a valid NIF number." );1055
1056/*
1057* Numer identyfikacji podatkowej ( NIP ) is the way tax identification used in Poland for companies
1058*/
1059$.validator.addMethod( "nipPL", function( value ) {1060"use strict";1061
1062value = value.replace( /[^0-9]/g, "" );1063
1064if ( value.length !== 10 ) {1065return false;1066}1067
1068var arrSteps = [ 6, 5, 7, 2, 3, 4, 5, 6, 7 ];1069var intSum = 0;1070for ( var i = 0; i < 9; i++ ) {1071intSum += arrSteps[ i ] * value[ i ];1072}1073var int2 = intSum % 11;1074var intControlNr = ( int2 === 10 ) ? 0 : int2;1075
1076return ( intControlNr === parseInt( value[ 9 ], 10 ) );1077}, "Please specify a valid NIP number." );1078
1079/**
1080* Created for project jquery-validation.
1081* @Description Brazillian PIS or NIS number (Número de Identificação Social Pis ou Pasep) is the equivalent of a
1082* Brazilian tax registration number NIS of PIS numbers have 11 digits in total: 10 numbers followed by 1 check numbers
1083* that are being used for validation.
1084* @copyright (c) 21/08/2018 13:14, Cleiton da Silva Mendonça
1085* @author Cleiton da Silva Mendonça <cleiton.mendonca@gmail.com>
1086* @link http://gitlab.com/csmendonca Gitlab of Cleiton da Silva Mendonça
1087* @link http://github.com/csmendonca Github of Cleiton da Silva Mendonça
1088*/
1089$.validator.addMethod( "nisBR", function( value ) {1090var number;1091var cn;1092var sum = 0;1093var dv;1094var count;1095var multiplier;1096
1097// Removing special characters from value1098value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );1099
1100// Checking value to have 11 digits only1101if ( value.length !== 11 ) {1102return false;1103}1104
1105//Get check number of value1106cn = parseInt( value.substring( 10, 11 ), 10 );1107
1108//Get number with 10 digits of the value1109number = parseInt( value.substring( 0, 10 ), 10 );1110
1111for ( count = 2; count < 12; count++ ) {1112multiplier = count;1113if ( count === 10 ) {1114multiplier = 2;1115}1116if ( count === 11 ) {1117multiplier = 3;1118}1119sum += ( ( number % 10 ) * multiplier );1120number = parseInt( number / 10, 10 );1121}1122dv = ( sum % 11 );1123
1124if ( dv > 1 ) {1125dv = ( 11 - dv );1126} else {1127dv = 0;1128}1129
1130if ( cn === dv ) {1131return true;1132} else {1133return false;1134}1135}, "Please specify a valid NIS/PIS number" );1136
1137$.validator.addMethod( "notEqualTo", function( value, element, param ) {1138return this.optional( element ) || !$.validator.methods.equalTo.call( this, value, element, param );1139}, "Please enter a different value, values must not be the same." );1140
1141$.validator.addMethod( "nowhitespace", function( value, element ) {1142return this.optional( element ) || /^\S+$/i.test( value );1143}, "No white space please" );1144
1145/**
1146* Return true if the field value matches the given format RegExp
1147*
1148* @example $.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)
1149* @result true
1150*
1151* @example $.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)
1152* @result false
1153*
1154* @name $.validator.methods.pattern
1155* @type Boolean
1156* @cat Plugins/Validate/Methods
1157*/
1158$.validator.addMethod( "pattern", function( value, element, param ) {1159if ( this.optional( element ) ) {1160return true;1161}1162if ( typeof param === "string" ) {1163param = new RegExp( "^(?:" + param + ")$" );1164}1165return param.test( value );1166}, "Invalid format." );1167
1168/**
1169* Dutch phone numbers have 10 digits (or 11 and start with +31).
1170*/
1171$.validator.addMethod( "phoneNL", function( value, element ) {1172return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test( value );1173}, "Please specify a valid phone number." );1174
1175/**
1176* Polish telephone numbers have 9 digits.
1177*
1178* Mobile phone numbers starts with following digits:
1179* 45, 50, 51, 53, 57, 60, 66, 69, 72, 73, 78, 79, 88.
1180*
1181* Fixed-line numbers starts with area codes:
1182* 12, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 29, 32, 33,
1183* 34, 41, 42, 43, 44, 46, 48, 52, 54, 55, 56, 58, 59, 61,
1184* 62, 63, 65, 67, 68, 71, 74, 75, 76, 77, 81, 82, 83, 84,
1185* 85, 86, 87, 89, 91, 94, 95.
1186*
1187* Ministry of National Defence numbers and VoIP numbers starts with 26 and 39.
1188*
1189* Excludes intelligent networks (premium rate, shared cost, free phone numbers).
1190*
1191* Poland National Numbering Plan http://www.itu.int/oth/T02020000A8/en
1192*/
1193$.validator.addMethod( "phonePL", function( phone_number, element ) {1194phone_number = phone_number.replace( /\s+/g, "" );1195var regexp = /^(?:(?:(?:\+|00)?48)|(?:\(\+?48\)))?(?:1[2-8]|2[2-69]|3[2-49]|4[1-68]|5[0-9]|6[0-35-9]|[7-8][1-9]|9[145])\d{7}$/;1196return this.optional( element ) || regexp.test( phone_number );1197}, "Please specify a valid phone number" );1198
1199/* For UK phone functions, do the following server side processing:
1200* Compare original input with this RegEx pattern:
1201* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
1202* Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
1203* Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
1204* A number of very detailed GB telephone number RegEx patterns can also be found at:
1205* http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
1206*/
1207
1208// Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
1209$.validator.addMethod( "phonesUK", function( phone_number, element ) {1210phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );1211return this.optional( element ) || phone_number.length > 9 &&1212phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/ );1213}, "Please specify a valid uk phone number" );1214
1215/* For UK phone functions, do the following server side processing:
1216* Compare original input with this RegEx pattern:
1217* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
1218* Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
1219* Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
1220* A number of very detailed GB telephone number RegEx patterns can also be found at:
1221* http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
1222*/
1223$.validator.addMethod( "phoneUK", function( phone_number, element ) {1224phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );1225return this.optional( element ) || phone_number.length > 9 &&1226phone_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})$/ );1227}, "Please specify a valid phone number" );1228
1229/**
1230* Matches US phone number format
1231*
1232* where the area code may not start with 1 and the prefix may not start with 1
1233* allows '-' or ' ' as a separator and allows parens around area code
1234* some people may want to put a '1' in front of their number
1235*
1236* 1(212)-999-2345 or
1237* 212 999 2344 or
1238* 212-999-0983
1239*
1240* but not
1241* 111-123-5434
1242* and not
1243* 212 123 4567
1244*/
1245$.validator.addMethod( "phoneUS", function( phone_number, element ) {1246phone_number = phone_number.replace( /\s+/g, "" );1247return this.optional( element ) || phone_number.length > 9 &&1248phone_number.match( /^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]\d{2}-?\d{4}$/ );1249}, "Please specify a valid phone number" );1250
1251/*
1252* Valida CEPs do brasileiros:
1253*
1254* Formatos aceitos:
1255* 99999-999
1256* 99.999-999
1257* 99999999
1258*/
1259$.validator.addMethod( "postalcodeBR", function( cep_value, element ) {1260return this.optional( element ) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );1261}, "Informe um CEP válido." );1262
1263/**
1264* Matches a valid Canadian Postal Code
1265*
1266* @example jQuery.validator.methods.postalCodeCA( "H0H 0H0", element )
1267* @result true
1268*
1269* @example jQuery.validator.methods.postalCodeCA( "H0H0H0", element )
1270* @result false
1271*
1272* @name jQuery.validator.methods.postalCodeCA
1273* @type Boolean
1274* @cat Plugins/Validate/Methods
1275*/
1276$.validator.addMethod( "postalCodeCA", function( value, element ) {1277return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test( value );1278}, "Please specify a valid postal code" );1279
1280/* Matches Italian postcode (CAP) */
1281$.validator.addMethod( "postalcodeIT", function( value, element ) {1282return this.optional( element ) || /^\d{5}$/.test( value );1283}, "Please specify a valid postal code" );1284
1285$.validator.addMethod( "postalcodeNL", function( value, element ) {1286return this.optional( element ) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test( value );1287}, "Please specify a valid postal code" );1288
1289// Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK)
1290$.validator.addMethod( "postcodeUK", function( value, element ) {1291return 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 );1292}, "Please specify a valid UK postcode" );1293
1294/*
1295* Lets you say "at least X inputs that match selector Y must be filled."
1296*
1297* The end result is that neither of these inputs:
1298*
1299* <input class="productinfo" name="partnumber">
1300* <input class="productinfo" name="description">
1301*
1302* ...will validate unless at least one of them is filled.
1303*
1304* partnumber: {require_from_group: [1,".productinfo"]},
1305* description: {require_from_group: [1,".productinfo"]}
1306*
1307* options[0]: number of fields that must be filled in the group
1308* options[1]: CSS selector that defines the group of conditionally required fields
1309*/
1310$.validator.addMethod( "require_from_group", function( value, element, options ) {1311var $fields = $( options[ 1 ], element.form ),1312$fieldsFirst = $fields.eq( 0 ),1313validator = $fieldsFirst.data( "valid_req_grp" ) ? $fieldsFirst.data( "valid_req_grp" ) : $.extend( {}, this ),1314isValid = $fields.filter( function() {1315return validator.elementValue( this );1316} ).length >= options[ 0 ];1317
1318// Store the cloned validator for future validation1319$fieldsFirst.data( "valid_req_grp", validator );1320
1321// If element isn't being validated, run each require_from_group field's validation rules1322if ( !$( element ).data( "being_validated" ) ) {1323$fields.data( "being_validated", true );1324$fields.each( function() {1325validator.element( this );1326} );1327$fields.data( "being_validated", false );1328}1329return isValid;1330}, $.validator.format( "Please fill at least {0} of these fields." ) );1331
1332/*
1333* Lets you say "either at least X inputs that match selector Y must be filled,
1334* OR they must all be skipped (left blank)."
1335*
1336* The end result, is that none of these inputs:
1337*
1338* <input class="productinfo" name="partnumber">
1339* <input class="productinfo" name="description">
1340* <input class="productinfo" name="color">
1341*
1342* ...will validate unless either at least two of them are filled,
1343* OR none of them are.
1344*
1345* partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
1346* description: {skip_or_fill_minimum: [2,".productinfo"]},
1347* color: {skip_or_fill_minimum: [2,".productinfo"]}
1348*
1349* options[0]: number of fields that must be filled in the group
1350* options[1]: CSS selector that defines the group of conditionally required fields
1351*
1352*/
1353$.validator.addMethod( "skip_or_fill_minimum", function( value, element, options ) {1354var $fields = $( options[ 1 ], element.form ),1355$fieldsFirst = $fields.eq( 0 ),1356validator = $fieldsFirst.data( "valid_skip" ) ? $fieldsFirst.data( "valid_skip" ) : $.extend( {}, this ),1357numberFilled = $fields.filter( function() {1358return validator.elementValue( this );1359} ).length,1360isValid = numberFilled === 0 || numberFilled >= options[ 0 ];1361
1362// Store the cloned validator for future validation1363$fieldsFirst.data( "valid_skip", validator );1364
1365// If element isn't being validated, run each skip_or_fill_minimum field's validation rules1366if ( !$( element ).data( "being_validated" ) ) {1367$fields.data( "being_validated", true );1368$fields.each( function() {1369validator.element( this );1370} );1371$fields.data( "being_validated", false );1372}1373return isValid;1374}, $.validator.format( "Please either skip these fields or fill at least {0} of them." ) );1375
1376/* Validates US States and/or Territories by @jdforsythe
1377* Can be case insensitive or require capitalization - default is case insensitive
1378* Can include US Territories or not - default does not
1379* Can include US Military postal abbreviations (AA, AE, AP) - default does not
1380*
1381* Note: "States" always includes DC (District of Colombia)
1382*
1383* Usage examples:
1384*
1385* This is the default - case insensitive, no territories, no military zones
1386* stateInput: {
1387* caseSensitive: false,
1388* includeTerritories: false,
1389* includeMilitary: false
1390* }
1391*
1392* Only allow capital letters, no territories, no military zones
1393* stateInput: {
1394* caseSensitive: false
1395* }
1396*
1397* Case insensitive, include territories but not military zones
1398* stateInput: {
1399* includeTerritories: true
1400* }
1401*
1402* Only allow capital letters, include territories and military zones
1403* stateInput: {
1404* caseSensitive: true,
1405* includeTerritories: true,
1406* includeMilitary: true
1407* }
1408*
1409*/
1410$.validator.addMethod( "stateUS", function( value, element, options ) {1411var isDefault = typeof options === "undefined",1412caseSensitive = ( isDefault || typeof options.caseSensitive === "undefined" ) ? false : options.caseSensitive,1413includeTerritories = ( isDefault || typeof options.includeTerritories === "undefined" ) ? false : options.includeTerritories,1414includeMilitary = ( isDefault || typeof options.includeMilitary === "undefined" ) ? false : options.includeMilitary,1415regex;1416
1417if ( !includeTerritories && !includeMilitary ) {1418regex = "^(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$";1419} else if ( includeTerritories && includeMilitary ) {1420regex = "^(A[AEKLPRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";1421} else if ( includeTerritories ) {1422regex = "^(A[KLRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$";1423} else {1424regex = "^(A[AEKLPRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$";1425}1426
1427regex = caseSensitive ? new RegExp( regex ) : new RegExp( regex, "i" );1428return this.optional( element ) || regex.test( value );1429}, "Please specify a valid state" );1430
1431// TODO check if value starts with <, otherwise don't try stripping anything
1432$.validator.addMethod( "strippedminlength", function( value, element, param ) {1433return $( value ).text().length >= param;1434}, $.validator.format( "Please enter at least {0} characters" ) );1435
1436$.validator.addMethod( "time", function( value, element ) {1437return this.optional( element ) || /^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test( value );1438}, "Please enter a valid time, between 00:00 and 23:59" );1439
1440$.validator.addMethod( "time12h", function( value, element ) {1441return this.optional( element ) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test( value );1442}, "Please enter a valid time in 12-hour am/pm format" );1443
1444// Same as url, but TLD is optional
1445$.validator.addMethod( "url2", function( value, element ) {1446return 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 );1447}, $.validator.messages.url );1448
1449/**
1450* Return true, if the value is a valid vehicle identification number (VIN).
1451*
1452* Works with all kind of text inputs.
1453*
1454* @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
1455* @desc Declares a required input element whose value must be a valid vehicle identification number.
1456*
1457* @name $.validator.methods.vinUS
1458* @type Boolean
1459* @cat Plugins/Validate/Methods
1460*/
1461$.validator.addMethod( "vinUS", function( v ) {1462if ( v.length !== 17 ) {1463return false;1464}1465
1466var LL = [ "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ],1467VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],1468FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],1469rs = 0,1470i, n, d, f, cd, cdv;1471
1472for ( i = 0; i < 17; i++ ) {1473f = FL[ i ];1474d = v.slice( i, i + 1 );1475if ( i === 8 ) {1476cdv = d;1477}1478if ( !isNaN( d ) ) {1479d *= f;1480} else {1481for ( n = 0; n < LL.length; n++ ) {1482if ( d.toUpperCase() === LL[ n ] ) {1483d = VL[ n ];1484d *= f;1485if ( isNaN( cdv ) && n === 8 ) {1486cdv = LL[ n ];1487}1488break;1489}1490}1491}1492rs += d;1493}1494cd = rs % 11;1495if ( cd === 10 ) {1496cd = "X";1497}1498if ( cd === cdv ) {1499return true;1500}1501return false;1502}, "The specified vehicle identification number (VIN) is invalid." );1503
1504$.validator.addMethod( "zipcodeUS", function( value, element ) {1505return this.optional( element ) || /^\d{5}(-\d{4})?$/.test( value );1506}, "The specified US ZIP Code is invalid" );1507
1508$.validator.addMethod( "ziprange", function( value, element ) {1509return this.optional( element ) || /^90[2-5]\d\{2\}-\d{4}$/.test( value );1510}, "Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx" );1511return $;1512}));