You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1512 lines
51KB

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