commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / bower_components / jquery-validation / src / additional / vinUS.js
1 /**
2 * Return true, if the value is a valid vehicle identification number (VIN).
3 *
4 * Works with all kind of text inputs.
5 *
6 * @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
7 * @desc Declares a required input element whose value must be a valid vehicle identification number.
8 *
9 * @name $.validator.methods.vinUS
10 * @type Boolean
11 * @cat Plugins/Validate/Methods
12 */
13 $.validator.addMethod("vinUS", function(v) {
14 if (v.length !== 17) {
15 return false;
16 }
17
18 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" ],
19 VL = [ 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 7, 9, 2, 3, 4, 5, 6, 7, 8, 9 ],
20 FL = [ 8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2 ],
21 rs = 0,
22 i, n, d, f, cd, cdv;
23
24 for (i = 0; i < 17; i++) {
25 f = FL[i];
26 d = v.slice(i, i + 1);
27 if (i === 8) {
28 cdv = d;
29 }
30 if (!isNaN(d)) {
31 d *= f;
32 } else {
33 for (n = 0; n < LL.length; n++) {
34 if (d.toUpperCase() === LL[n]) {
35 d = VL[n];
36 d *= f;
37 if (isNaN(cdv) && n === 8) {
38 cdv = LL[n];
39 }
40 break;
41 }
42 }
43 }
44 rs += d;
45 }
46 cd = rs % 11;
47 if (cd === 10) {
48 cd = "X";
49 }
50 if (cd === cdv) {
51 return true;
52 }
53 return false;
54 }, "The specified vehicle identification number (VIN) is invalid.");