additional-methods.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /*!
  2. * jQuery Validation Plugin v1.13.1
  3. *
  4. * http://jqueryvalidation.org/
  5. *
  6. * Copyright (c) 2014 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. (function() {
  17. function stripHtml(value) {
  18. // remove html tags and space chars
  19. return value.replace(/<.[^<>]*?>/g, " ").replace(/&nbsp;|&#160;/gi, " ")
  20. // remove punctuation
  21. .replace(/[.(),;:!?%#$'\"_+=\/\-“”’]*/g, "");
  22. }
  23. $.validator.addMethod("maxWords", function(value, element, params) {
  24. return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length <= params;
  25. }, $.validator.format("Please enter {0} words or less."));
  26. $.validator.addMethod("minWords", function(value, element, params) {
  27. return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params;
  28. }, $.validator.format("Please enter at least {0} words."));
  29. $.validator.addMethod("rangeWords", function(value, element, params) {
  30. var valueStripped = stripHtml(value),
  31. regex = /\b\w+\b/g;
  32. return this.optional(element) || valueStripped.match(regex).length >= params[0] && valueStripped.match(regex).length <= params[1];
  33. }, $.validator.format("Please enter between {0} and {1} words."));
  34. }());
  35. // Accept a value from a file input based on a required mimetype
  36. $.validator.addMethod("accept", function(value, element, param) {
  37. // Split mime on commas in case we have multiple types we can accept
  38. var typeParam = typeof param === "string" ? param.replace(/\s/g, "").replace(/,/g, "|") : "image/*",
  39. optionalValue = this.optional(element),
  40. i, file;
  41. // Element is optional
  42. if (optionalValue) {
  43. return optionalValue;
  44. }
  45. if ($(element).attr("type") === "file") {
  46. // If we are using a wildcard, make it regex friendly
  47. typeParam = typeParam.replace(/\*/g, ".*");
  48. // Check if the element has a FileList before checking each file
  49. if (element.files && element.files.length) {
  50. for (i = 0; i < element.files.length; i++) {
  51. file = element.files[i];
  52. // Grab the mimetype from the loaded file, verify it matches
  53. if (!file.type.match(new RegExp( ".?(" + typeParam + ")$", "i"))) {
  54. return false;
  55. }
  56. }
  57. }
  58. }
  59. // Either return true because we've validated each file, or because the
  60. // browser does not support element.files and the FileList feature
  61. return true;
  62. }, $.validator.format("Please enter a value with a valid mimetype."));
  63. $.validator.addMethod("alphanumeric", function(value, element) {
  64. return this.optional(element) || /^\w+$/i.test(value);
  65. }, "Letters, numbers, and underscores only please");
  66. /*
  67. * Dutch bank account numbers (not 'giro' numbers) have 9 digits
  68. * and pass the '11 check'.
  69. * We accept the notation with spaces, as that is common.
  70. * acceptable: 123456789 or 12 34 56 789
  71. */
  72. $.validator.addMethod("bankaccountNL", function(value, element) {
  73. if (this.optional(element)) {
  74. return true;
  75. }
  76. if (!(/^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test(value))) {
  77. return false;
  78. }
  79. // now '11 check'
  80. var account = value.replace(/ /g, ""), // remove spaces
  81. sum = 0,
  82. len = account.length,
  83. pos, factor, digit;
  84. for ( pos = 0; pos < len; pos++ ) {
  85. factor = len - pos;
  86. digit = account.substring(pos, pos + 1);
  87. sum = sum + factor * digit;
  88. }
  89. return sum % 11 === 0;
  90. }, "Please specify a valid bank account number");
  91. $.validator.addMethod("bankorgiroaccountNL", function(value, element) {
  92. return this.optional(element) ||
  93. ($.validator.methods.bankaccountNL.call(this, value, element)) ||
  94. ($.validator.methods.giroaccountNL.call(this, value, element));
  95. }, "Please specify a valid bank or giro account number");
  96. /**
  97. * BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity.
  98. *
  99. * BIC pattern: BBBBCCLLbbb (8 or 11 characters long; bbb is optional)
  100. *
  101. * BIC definition in detail:
  102. * - First 4 characters - bank code (only letters)
  103. * - Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
  104. * - Next 2 characters - location code (letters and digits)
  105. * a. shall not start with '0' or '1'
  106. * 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)
  107. * - Last 3 characters - branch code, optional (shall not start with 'X' except in case of 'XXX' for primary office) (letters and digits)
  108. */
  109. $.validator.addMethod("bic", function(value, element) {
  110. 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 );
  111. }, "Please specify a valid BIC code");
  112. /*
  113. * Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
  114. * Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
  115. */
  116. $.validator.addMethod( "cifES", function( value ) {
  117. "use strict";
  118. var num = [],
  119. controlDigit, sum, i, count, tmp, secondDigit;
  120. value = value.toUpperCase();
  121. // Quick format test
  122. 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}$)" ) ) {
  123. return false;
  124. }
  125. for ( i = 0; i < 9; i++ ) {
  126. num[ i ] = parseInt( value.charAt( i ), 10 );
  127. }
  128. // Algorithm for checking CIF codes
  129. sum = num[ 2 ] + num[ 4 ] + num[ 6 ];
  130. for ( count = 1; count < 8; count += 2 ) {
  131. tmp = ( 2 * num[ count ] ).toString();
  132. secondDigit = tmp.charAt( 1 );
  133. sum += parseInt( tmp.charAt( 0 ), 10 ) + ( secondDigit === "" ? 0 : parseInt( secondDigit, 10 ) );
  134. }
  135. /* The first (position 1) is a letter following the following criteria:
  136. * A. Corporations
  137. * B. LLCs
  138. * C. General partnerships
  139. * D. Companies limited partnerships
  140. * E. Communities of goods
  141. * F. Cooperative Societies
  142. * G. Associations
  143. * H. Communities of homeowners in horizontal property regime
  144. * J. Civil Societies
  145. * K. Old format
  146. * L. Old format
  147. * M. Old format
  148. * N. Nonresident entities
  149. * P. Local authorities
  150. * Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions
  151. * R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)
  152. * S. Organs of State Administration and regions
  153. * V. Agrarian Transformation
  154. * W. Permanent establishments of non-resident in Spain
  155. */
  156. if ( /^[ABCDEFGHJNPQRSUVW]{1}/.test( value ) ) {
  157. sum += "";
  158. controlDigit = 10 - parseInt( sum.charAt( sum.length - 1 ), 10 );
  159. value += controlDigit;
  160. return ( num[ 8 ].toString() === String.fromCharCode( 64 + controlDigit ) || num[ 8 ].toString() === value.charAt( value.length - 1 ) );
  161. }
  162. return false;
  163. }, "Please specify a valid CIF number." );
  164. /* NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
  165. * Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
  166. * Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
  167. */
  168. $.validator.addMethod("creditcardtypes", function(value, element, param) {
  169. if (/[^0-9\-]+/.test(value)) {
  170. return false;
  171. }
  172. value = value.replace(/\D/g, "");
  173. var validTypes = 0x0000;
  174. if (param.mastercard) {
  175. validTypes |= 0x0001;
  176. }
  177. if (param.visa) {
  178. validTypes |= 0x0002;
  179. }
  180. if (param.amex) {
  181. validTypes |= 0x0004;
  182. }
  183. if (param.dinersclub) {
  184. validTypes |= 0x0008;
  185. }
  186. if (param.enroute) {
  187. validTypes |= 0x0010;
  188. }
  189. if (param.discover) {
  190. validTypes |= 0x0020;
  191. }
  192. if (param.jcb) {
  193. validTypes |= 0x0040;
  194. }
  195. if (param.unknown) {
  196. validTypes |= 0x0080;
  197. }
  198. if (param.all) {
  199. validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
  200. }
  201. if (validTypes & 0x0001 && /^(5[12345])/.test(value)) { //mastercard
  202. return value.length === 16;
  203. }
  204. if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa
  205. return value.length === 16;
  206. }
  207. if (validTypes & 0x0004 && /^(3[47])/.test(value)) { //amex
  208. return value.length === 15;
  209. }
  210. if (validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test(value)) { //dinersclub
  211. return value.length === 14;
  212. }
  213. if (validTypes & 0x0010 && /^(2(014|149))/.test(value)) { //enroute
  214. return value.length === 15;
  215. }
  216. if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover
  217. return value.length === 16;
  218. }
  219. if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb
  220. return value.length === 16;
  221. }
  222. if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb
  223. return value.length === 15;
  224. }
  225. if (validTypes & 0x0080) { //unknown
  226. return true;
  227. }
  228. return false;
  229. }, "Please enter a valid credit card number.");
  230. /**
  231. * Validates currencies with any given symbols by @jameslouiz
  232. * Symbols can be optional or required. Symbols required by default
  233. *
  234. * Usage examples:
  235. * currency: ["£", false] - Use false for soft currency validation
  236. * currency: ["$", false]
  237. * currency: ["RM", false] - also works with text based symbols such as "RM" - Malaysia Ringgit etc
  238. *
  239. * <input class="currencyInput" name="currencyInput">
  240. *
  241. * Soft symbol checking
  242. * currencyInput: {
  243. * currency: ["$", false]
  244. * }
  245. *
  246. * Strict symbol checking (default)
  247. * currencyInput: {
  248. * currency: "$"
  249. * //OR
  250. * currency: ["$", true]
  251. * }
  252. *
  253. * Multiple Symbols
  254. * currencyInput: {
  255. * currency: "$,£,¢"
  256. * }
  257. */
  258. $.validator.addMethod("currency", function(value, element, param) {
  259. var isParamString = typeof param === "string",
  260. symbol = isParamString ? param : param[0],
  261. soft = isParamString ? true : param[1],
  262. regex;
  263. symbol = symbol.replace(/,/g, "");
  264. symbol = soft ? symbol + "]" : symbol + "]?";
  265. 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})?)$";
  266. regex = new RegExp(regex);
  267. return this.optional(element) || regex.test(value);
  268. }, "Please specify a valid currency");
  269. $.validator.addMethod("dateFA", function(value, element) {
  270. 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);
  271. }, "Please enter a correct date");
  272. /**
  273. * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
  274. *
  275. * @example $.validator.methods.date("01/01/1900")
  276. * @result true
  277. *
  278. * @example $.validator.methods.date("01/13/1990")
  279. * @result false
  280. *
  281. * @example $.validator.methods.date("01.01.1900")
  282. * @result false
  283. *
  284. * @example <input name="pippo" class="{dateITA:true}" />
  285. * @desc Declares an optional input element whose value must be a valid date.
  286. *
  287. * @name $.validator.methods.dateITA
  288. * @type Boolean
  289. * @cat Plugins/Validate/Methods
  290. */
  291. $.validator.addMethod("dateITA", function(value, element) {
  292. var check = false,
  293. re = /^\d{1,2}\/\d{1,2}\/\d{4}$/,
  294. adata, gg, mm, aaaa, xdata;
  295. if ( re.test(value)) {
  296. adata = value.split("/");
  297. gg = parseInt(adata[0], 10);
  298. mm = parseInt(adata[1], 10);
  299. aaaa = parseInt(adata[2], 10);
  300. xdata = new Date(aaaa, mm - 1, gg, 12, 0, 0, 0);
  301. if ( ( xdata.getUTCFullYear() === aaaa ) && ( xdata.getUTCMonth () === mm - 1 ) && ( xdata.getUTCDate() === gg ) ) {
  302. check = true;
  303. } else {
  304. check = false;
  305. }
  306. } else {
  307. check = false;
  308. }
  309. return this.optional(element) || check;
  310. }, "Please enter a correct date");
  311. $.validator.addMethod("dateNL", function(value, element) {
  312. return this.optional(element) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(value);
  313. }, "Please enter a correct date");
  314. // Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept
  315. $.validator.addMethod("extension", function(value, element, param) {
  316. param = typeof param === "string" ? param.replace(/,/g, "|") : "png|jpe?g|gif";
  317. return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
  318. }, $.validator.format("Please enter a value with a valid extension."));
  319. /**
  320. * Dutch giro account numbers (not bank numbers) have max 7 digits
  321. */
  322. $.validator.addMethod("giroaccountNL", function(value, element) {
  323. return this.optional(element) || /^[0-9]{1,7}$/.test(value);
  324. }, "Please specify a valid giro account number");
  325. /**
  326. * IBAN is the international bank account number.
  327. * It has a country - specific format, that is checked here too
  328. */
  329. $.validator.addMethod("iban", function(value, element) {
  330. // some quick simple tests to prevent needless work
  331. if (this.optional(element)) {
  332. return true;
  333. }
  334. // remove spaces and to upper case
  335. var iban = value.replace(/ /g, "").toUpperCase(),
  336. ibancheckdigits = "",
  337. leadingZeroes = true,
  338. cRest = "",
  339. cOperator = "",
  340. countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;
  341. if (!(/^([a-zA-Z0-9]{4} ){2,8}[a-zA-Z0-9]{1,4}|[a-zA-Z0-9]{12,34}$/.test(iban))) {
  342. return false;
  343. }
  344. // check the country code and find the country specific format
  345. countrycode = iban.substring(0, 2);
  346. bbancountrypatterns = {
  347. "AL": "\\d{8}[\\dA-Z]{16}",
  348. "AD": "\\d{8}[\\dA-Z]{12}",
  349. "AT": "\\d{16}",
  350. "AZ": "[\\dA-Z]{4}\\d{20}",
  351. "BE": "\\d{12}",
  352. "BH": "[A-Z]{4}[\\dA-Z]{14}",
  353. "BA": "\\d{16}",
  354. "BR": "\\d{23}[A-Z][\\dA-Z]",
  355. "BG": "[A-Z]{4}\\d{6}[\\dA-Z]{8}",
  356. "CR": "\\d{17}",
  357. "HR": "\\d{17}",
  358. "CY": "\\d{8}[\\dA-Z]{16}",
  359. "CZ": "\\d{20}",
  360. "DK": "\\d{14}",
  361. "DO": "[A-Z]{4}\\d{20}",
  362. "EE": "\\d{16}",
  363. "FO": "\\d{14}",
  364. "FI": "\\d{14}",
  365. "FR": "\\d{10}[\\dA-Z]{11}\\d{2}",
  366. "GE": "[\\dA-Z]{2}\\d{16}",
  367. "DE": "\\d{18}",
  368. "GI": "[A-Z]{4}[\\dA-Z]{15}",
  369. "GR": "\\d{7}[\\dA-Z]{16}",
  370. "GL": "\\d{14}",
  371. "GT": "[\\dA-Z]{4}[\\dA-Z]{20}",
  372. "HU": "\\d{24}",
  373. "IS": "\\d{22}",
  374. "IE": "[\\dA-Z]{4}\\d{14}",
  375. "IL": "\\d{19}",
  376. "IT": "[A-Z]\\d{10}[\\dA-Z]{12}",
  377. "KZ": "\\d{3}[\\dA-Z]{13}",
  378. "KW": "[A-Z]{4}[\\dA-Z]{22}",
  379. "LV": "[A-Z]{4}[\\dA-Z]{13}",
  380. "LB": "\\d{4}[\\dA-Z]{20}",
  381. "LI": "\\d{5}[\\dA-Z]{12}",
  382. "LT": "\\d{16}",
  383. "LU": "\\d{3}[\\dA-Z]{13}",
  384. "MK": "\\d{3}[\\dA-Z]{10}\\d{2}",
  385. "MT": "[A-Z]{4}\\d{5}[\\dA-Z]{18}",
  386. "MR": "\\d{23}",
  387. "MU": "[A-Z]{4}\\d{19}[A-Z]{3}",
  388. "MC": "\\d{10}[\\dA-Z]{11}\\d{2}",
  389. "MD": "[\\dA-Z]{2}\\d{18}",
  390. "ME": "\\d{18}",
  391. "NL": "[A-Z]{4}\\d{10}",
  392. "NO": "\\d{11}",
  393. "PK": "[\\dA-Z]{4}\\d{16}",
  394. "PS": "[\\dA-Z]{4}\\d{21}",
  395. "PL": "\\d{24}",
  396. "PT": "\\d{21}",
  397. "RO": "[A-Z]{4}[\\dA-Z]{16}",
  398. "SM": "[A-Z]\\d{10}[\\dA-Z]{12}",
  399. "SA": "\\d{2}[\\dA-Z]{18}",
  400. "RS": "\\d{18}",
  401. "SK": "\\d{20}",
  402. "SI": "\\d{15}",
  403. "ES": "\\d{20}",
  404. "SE": "\\d{20}",
  405. "CH": "\\d{5}[\\dA-Z]{12}",
  406. "TN": "\\d{20}",
  407. "TR": "\\d{5}[\\dA-Z]{17}",
  408. "AE": "\\d{3}\\d{16}",
  409. "GB": "[A-Z]{4}\\d{14}",
  410. "VG": "[\\dA-Z]{4}\\d{16}"
  411. };
  412. bbanpattern = bbancountrypatterns[countrycode];
  413. // As new countries will start using IBAN in the
  414. // future, we only check if the countrycode is known.
  415. // This prevents false negatives, while almost all
  416. // false positives introduced by this, will be caught
  417. // by the checksum validation below anyway.
  418. // Strict checking should return FALSE for unknown
  419. // countries.
  420. if (typeof bbanpattern !== "undefined") {
  421. ibanregexp = new RegExp("^[A-Z]{2}\\d{2}" + bbanpattern + "$", "");
  422. if (!(ibanregexp.test(iban))) {
  423. return false; // invalid country specific format
  424. }
  425. }
  426. // now check the checksum, first convert to digits
  427. ibancheck = iban.substring(4, iban.length) + iban.substring(0, 4);
  428. for (i = 0; i < ibancheck.length; i++) {
  429. charAt = ibancheck.charAt(i);
  430. if (charAt !== "0") {
  431. leadingZeroes = false;
  432. }
  433. if (!leadingZeroes) {
  434. ibancheckdigits += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(charAt);
  435. }
  436. }
  437. // calculate the result of: ibancheckdigits % 97
  438. for (p = 0; p < ibancheckdigits.length; p++) {
  439. cChar = ibancheckdigits.charAt(p);
  440. cOperator = "" + cRest + "" + cChar;
  441. cRest = cOperator % 97;
  442. }
  443. return cRest === 1;
  444. }, "Please specify a valid IBAN");
  445. $.validator.addMethod("integer", function(value, element) {
  446. return this.optional(element) || /^-?\d+$/.test(value);
  447. }, "A positive or negative non-decimal number please");
  448. $.validator.addMethod("ipv4", function(value, element) {
  449. 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);
  450. }, "Please enter a valid IP v4 address.");
  451. $.validator.addMethod("ipv6", function(value, element) {
  452. 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);
  453. }, "Please enter a valid IP v6 address.");
  454. $.validator.addMethod("lettersonly", function(value, element) {
  455. return this.optional(element) || /^[a-z]+$/i.test(value);
  456. }, "Letters only please");
  457. $.validator.addMethod("letterswithbasicpunc", function(value, element) {
  458. return this.optional(element) || /^[a-z\-.,()'"\s]+$/i.test(value);
  459. }, "Letters or punctuation only please");
  460. $.validator.addMethod("mobileNL", function(value, element) {
  461. return this.optional(element) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test(value);
  462. }, "Please specify a valid mobile number");
  463. /* For UK phone functions, do the following server side processing:
  464. * Compare original input with this RegEx pattern:
  465. * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
  466. * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
  467. * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
  468. * A number of very detailed GB telephone number RegEx patterns can also be found at:
  469. * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
  470. */
  471. $.validator.addMethod("mobileUK", function(phone_number, element) {
  472. phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
  473. return this.optional(element) || phone_number.length > 9 &&
  474. phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/);
  475. }, "Please specify a valid mobile number");
  476. /*
  477. * The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain
  478. */
  479. $.validator.addMethod( "nieES", function( value ) {
  480. "use strict";
  481. value = value.toUpperCase();
  482. // Basic format test
  483. 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}$)" ) ) {
  484. return false;
  485. }
  486. // Test NIE
  487. //T
  488. if ( /^[T]{1}/.test( value ) ) {
  489. return ( value[ 8 ] === /^[T]{1}[A-Z0-9]{8}$/.test( value ) );
  490. }
  491. //XYZ
  492. if ( /^[XYZ]{1}/.test( value ) ) {
  493. return (
  494. value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt(
  495. value.replace( "X", "0" )
  496. .replace( "Y", "1" )
  497. .replace( "Z", "2" )
  498. .substring( 0, 8 ) % 23
  499. )
  500. );
  501. }
  502. return false;
  503. }, "Please specify a valid NIE number." );
  504. /*
  505. * The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
  506. */
  507. $.validator.addMethod( "nifES", function( value ) {
  508. "use strict";
  509. value = value.toUpperCase();
  510. // Basic format test
  511. 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}$)") ) {
  512. return false;
  513. }
  514. // Test NIF
  515. if ( /^[0-9]{8}[A-Z]{1}$/.test( value ) ) {
  516. return ( "TRWAGMYFPDXBNJZSQVHLCKE".charAt( value.substring( 8, 0 ) % 23 ) === value.charAt( 8 ) );
  517. }
  518. // Test specials NIF (starts with K, L or M)
  519. if ( /^[KLM]{1}/.test( value ) ) {
  520. return ( value[ 8 ] === String.fromCharCode( 64 ) );
  521. }
  522. return false;
  523. }, "Please specify a valid NIF number." );
  524. $.validator.addMethod("nowhitespace", function(value, element) {
  525. return this.optional(element) || /^\S+$/i.test(value);
  526. }, "No white space please");
  527. /**
  528. * Return true if the field value matches the given format RegExp
  529. *
  530. * @example $.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)
  531. * @result true
  532. *
  533. * @example $.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)
  534. * @result false
  535. *
  536. * @name $.validator.methods.pattern
  537. * @type Boolean
  538. * @cat Plugins/Validate/Methods
  539. */
  540. $.validator.addMethod("pattern", function(value, element, param) {
  541. if (this.optional(element)) {
  542. return true;
  543. }
  544. if (typeof param === "string") {
  545. param = new RegExp("^(?:" + param + ")$");
  546. }
  547. return param.test(value);
  548. }, "Invalid format.");
  549. /**
  550. * Dutch phone numbers have 10 digits (or 11 and start with +31).
  551. */
  552. $.validator.addMethod("phoneNL", function(value, element) {
  553. 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);
  554. }, "Please specify a valid phone number.");
  555. /* For UK phone functions, do the following server side processing:
  556. * Compare original input with this RegEx pattern:
  557. * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
  558. * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
  559. * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
  560. * A number of very detailed GB telephone number RegEx patterns can also be found at:
  561. * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
  562. */
  563. $.validator.addMethod("phoneUK", function(phone_number, element) {
  564. phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
  565. return this.optional(element) || phone_number.length > 9 &&
  566. 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})$/);
  567. }, "Please specify a valid phone number");
  568. /**
  569. * matches US phone number format
  570. *
  571. * where the area code may not start with 1 and the prefix may not start with 1
  572. * allows '-' or ' ' as a separator and allows parens around area code
  573. * some people may want to put a '1' in front of their number
  574. *
  575. * 1(212)-999-2345 or
  576. * 212 999 2344 or
  577. * 212-999-0983
  578. *
  579. * but not
  580. * 111-123-5434
  581. * and not
  582. * 212 123 4567
  583. */
  584. $.validator.addMethod("phoneUS", function(phone_number, element) {
  585. phone_number = phone_number.replace(/\s+/g, "");
  586. return this.optional(element) || phone_number.length > 9 &&
  587. 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}$/);
  588. }, "Please specify a valid phone number");
  589. /* For UK phone functions, do the following server side processing:
  590. * Compare original input with this RegEx pattern:
  591. * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
  592. * Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
  593. * Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
  594. * A number of very detailed GB telephone number RegEx patterns can also be found at:
  595. * http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
  596. */
  597. //Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
  598. $.validator.addMethod("phonesUK", function(phone_number, element) {
  599. phone_number = phone_number.replace(/\(|\)|\s+|-/g, "");
  600. return this.optional(element) || phone_number.length > 9 &&
  601. phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/);
  602. }, "Please specify a valid uk phone number");
  603. /**
  604. * Matches a valid Canadian Postal Code
  605. *
  606. * @example jQuery.validator.methods.postalCodeCA( "H0H 0H0", element )
  607. * @result true
  608. *
  609. * @example jQuery.validator.methods.postalCodeCA( "H0H0H0", element )
  610. * @result false
  611. *
  612. * @name jQuery.validator.methods.postalCodeCA
  613. * @type Boolean
  614. * @cat Plugins/Validate/Methods
  615. */
  616. $.validator.addMethod( "postalCodeCA", function( value, element ) {
  617. return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d$/.test( value );
  618. }, "Please specify a valid postal code" );
  619. /*
  620. * Valida CEPs do brasileiros:
  621. *
  622. * Formatos aceitos:
  623. * 99999-999
  624. * 99.999-999
  625. * 99999999
  626. */
  627. $.validator.addMethod("postalcodeBR", function(cep_value, element) {
  628. return this.optional(element) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );
  629. }, "Informe um CEP válido.");
  630. /* Matches Italian postcode (CAP) */
  631. $.validator.addMethod("postalcodeIT", function(value, element) {
  632. return this.optional(element) || /^\d{5}$/.test(value);
  633. }, "Please specify a valid postal code");
  634. $.validator.addMethod("postalcodeNL", function(value, element) {
  635. return this.optional(element) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test(value);
  636. }, "Please specify a valid postal code");
  637. // Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK)
  638. $.validator.addMethod("postcodeUK", function(value, element) {
  639. 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);
  640. }, "Please specify a valid UK postcode");
  641. /*
  642. * Lets you say "at least X inputs that match selector Y must be filled."
  643. *
  644. * The end result is that neither of these inputs:
  645. *
  646. * <input class="productinfo" name="partnumber">
  647. * <input class="productinfo" name="description">
  648. *
  649. * ...will validate unless at least one of them is filled.
  650. *
  651. * partnumber: {require_from_group: [1,".productinfo"]},
  652. * description: {require_from_group: [1,".productinfo"]}
  653. *
  654. * options[0]: number of fields that must be filled in the group
  655. * options[1]: CSS selector that defines the group of conditionally required fields
  656. */
  657. $.validator.addMethod("require_from_group", function(value, element, options) {
  658. var $fields = $(options[1], element.form),
  659. $fieldsFirst = $fields.eq(0),
  660. validator = $fieldsFirst.data("valid_req_grp") ? $fieldsFirst.data("valid_req_grp") : $.extend({}, this),
  661. isValid = $fields.filter(function() {
  662. return validator.elementValue(this);
  663. }).length >= options[0];
  664. // Store the cloned validator for future validation
  665. $fieldsFirst.data("valid_req_grp", validator);
  666. // If element isn't being validated, run each require_from_group field's validation rules
  667. if (!$(element).data("being_validated")) {
  668. $fields.data("being_validated", true);
  669. $fields.each(function() {
  670. validator.element(this);
  671. });
  672. $fields.data("being_validated", false);
  673. }
  674. return isValid;
  675. }, $.validator.format("Please fill at least {0} of these fields."));
  676. /*
  677. * Lets you say "either at least X inputs that match selector Y must be filled,
  678. * OR they must all be skipped (left blank)."
  679. *
  680. * The end result, is that none of these inputs:
  681. *
  682. * <input class="productinfo" name="partnumber">
  683. * <input class="productinfo" name="description">
  684. * <input class="productinfo" name="color">
  685. *
  686. * ...will validate unless either at least two of them are filled,
  687. * OR none of them are.
  688. *
  689. * partnumber: {skip_or_fill_minimum: [2,".productinfo"]},
  690. * description: {skip_or_fill_minimum: [2,".productinfo"]},
  691. * color: {skip_or_fill_minimum: [2,".productinfo"]}
  692. *
  693. * options[0]: number of fields that must be filled in the group
  694. * options[1]: CSS selector that defines the group of conditionally required fields
  695. *
  696. */
  697. $.validator.addMethod("skip_or_fill_minimum", function(value, element, options) {
  698. var $fields = $(options[1], element.form),
  699. $fieldsFirst = $fields.eq(0),
  700. validator = $fieldsFirst.data("valid_skip") ? $fieldsFirst.data("valid_skip") : $.extend({}, this),
  701. numberFilled = $fields.filter(function() {
  702. return validator.elementValue(this);
  703. }).length,
  704. isValid = numberFilled === 0 || numberFilled >= options[0];
  705. // Store the cloned validator for future validation
  706. $fieldsFirst.data("valid_skip", validator);
  707. // If element isn't being validated, run each skip_or_fill_minimum field's validation rules
  708. if (!$(element).data("being_validated")) {
  709. $fields.data("being_validated", true);
  710. $fields.each(function() {
  711. validator.element(this);
  712. });
  713. $fields.data("being_validated", false);
  714. }
  715. return isValid;
  716. }, $.validator.format("Please either skip these fields or fill at least {0} of them."));
  717. /* Validates US States and/or Territories by @jdforsythe
  718. * Can be case insensitive or require capitalization - default is case insensitive
  719. * Can include US Territories or not - default does not
  720. * Can include US Military postal abbreviations (AA, AE, AP) - default does not
  721. *
  722. * Note: "States" always includes DC (District of Colombia)
  723. *
  724. * Usage examples:
  725. *
  726. * This is the default - case insensitive, no territories, no military zones
  727. * stateInput: {
  728. * caseSensitive: false,
  729. * includeTerritories: false,
  730. * includeMilitary: false
  731. * }
  732. *
  733. * Only allow capital letters, no territories, no military zones
  734. * stateInput: {
  735. * caseSensitive: false
  736. * }
  737. *
  738. * Case insensitive, include territories but not military zones
  739. * stateInput: {
  740. * includeTerritories: true
  741. * }
  742. *
  743. * Only allow capital letters, include territories and military zones
  744. * stateInput: {
  745. * caseSensitive: true,
  746. * includeTerritories: true,
  747. * includeMilitary: true
  748. * }
  749. *
  750. *
  751. *
  752. */
  753. jQuery.validator.addMethod("stateUS", function(value, element, options) {
  754. var isDefault = typeof options === "undefined",
  755. caseSensitive = ( isDefault || typeof options.caseSensitive === "undefined" ) ? false : options.caseSensitive,
  756. includeTerritories = ( isDefault || typeof options.includeTerritories === "undefined" ) ? false : options.includeTerritories,
  757. includeMilitary = ( isDefault || typeof options.includeMilitary === "undefined" ) ? false : options.includeMilitary,
  758. regex;
  759. if (!includeTerritories && !includeMilitary) {
  760. 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])$";
  761. } else if (includeTerritories && includeMilitary) {
  762. 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])$";
  763. } else if (includeTerritories) {
  764. 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])$";
  765. } else {
  766. 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])$";
  767. }
  768. regex = caseSensitive ? new RegExp(regex) : new RegExp(regex, "i");
  769. return this.optional(element) || regex.test(value);
  770. },
  771. "Please specify a valid state");
  772. // TODO check if value starts with <, otherwise don't try stripping anything
  773. $.validator.addMethod("strippedminlength", function(value, element, param) {
  774. return $(value).text().length >= param;
  775. }, $.validator.format("Please enter at least {0} characters"));
  776. $.validator.addMethod("time", function(value, element) {
  777. return this.optional(element) || /^([01]\d|2[0-3])(:[0-5]\d){1,2}$/.test(value);
  778. }, "Please enter a valid time, between 00:00 and 23:59");
  779. $.validator.addMethod("time12h", function(value, element) {
  780. return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test(value);
  781. }, "Please enter a valid time in 12-hour am/pm format");
  782. // same as url, but TLD is optional
  783. $.validator.addMethod("url2", function(value, element) {
  784. 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);
  785. }, $.validator.messages.url);
  786. /**
  787. * Return true, if the value is a valid vehicle identification number (VIN).
  788. *
  789. * Works with all kind of text inputs.
  790. *
  791. * @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
  792. * @desc Declares a required input element whose value must be a valid vehicle identification number.
  793. *
  794. * @name $.validator.methods.vinUS
  795. * @type Boolean
  796. * @cat Plugins/Validate/Methods
  797. */
  798. $.validator.addMethod("vinUS", function(v) {
  799. if (v.length !== 17) {
  800. return false;
  801. }
  802. 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" ],
  803. VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
  804. FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
  805. rs = 0,
  806. i, n, d, f, cd, cdv;
  807. for (i = 0; i < 17; i++) {
  808. f = FL[i];
  809. d = v.slice(i, i + 1);
  810. if (i === 8) {
  811. cdv = d;
  812. }
  813. if (!isNaN(d)) {
  814. d *= f;
  815. } else {
  816. for (n = 0; n < LL.length; n++) {
  817. if (d.toUpperCase() === LL[n]) {
  818. d = VL[n];
  819. d *= f;
  820. if (isNaN(cdv) && n === 8) {
  821. cdv = LL[n];
  822. }
  823. break;
  824. }
  825. }
  826. }
  827. rs += d;
  828. }
  829. cd = rs % 11;
  830. if (cd === 10) {
  831. cd = "X";
  832. }
  833. if (cd === cdv) {
  834. return true;
  835. }
  836. return false;
  837. }, "The specified vehicle identification number (VIN) is invalid.");
  838. $.validator.addMethod("zipcodeUS", function(value, element) {
  839. return this.optional(element) || /^\d{5}(-\d{4})?$/.test(value);
  840. }, "The specified US ZIP Code is invalid");
  841. $.validator.addMethod("ziprange", function(value, element) {
  842. return this.optional(element) || /^90[2-5]\d\{2\}-\d{4}$/.test(value);
  843. }, "Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx");
  844. }));