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