Algorithm source:
Generally, the second digit of the Vehicle identification code is the test digit, which can be expressed by any number or letter "X" in 0-9. The meanings of numbers and letters at other locations may be different. However, after the other 16-digit VIN code is determined, the ninth digit is obtained using the following method.
First, convert the letters in the other 16 digits into numbers according to the following relationship:
A = 1 B = 2 C = 3 D = 4 E = 5 F = 6G = 7 H = 8 J = 1 K = 2 L = 3 M = 4 N = 5 P = 7 R = 9 S = 2 T = 3 U = 4 V = 5 W = 6 X = 7 Y = 8 Z = 9
Each position has a weighted number:
Location: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Weights: 8 7 6 5 4 3 2 10*9 8 7 6 5 4 3 2
At last, multiply the weighting coefficient of each of the 16 bits outside the test bit by the corresponding value of this bits, and then add the product, divide the sum obtained by 11, the remainder is the value of the test bit. If the remainder is 10, the test digit is the letter "X ".
JS Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var Arr = new Array ();
Var Brr = new Array ();
Arr ['a'] = 1;
Arr ['B'] = 2;
Arr ['C'] = 3;
Arr ['D'] = 4;
Arr ['E'] = 5;
Arr ['F'] = 6;
Arr ['G'] = 7;
Arr ['H'] = 8;
Arr ['J'] = 1;
Arr ['K'] = 2;
Arr ['l'] = 3;
Arr ['M'] = 4;
Arr ['n'] = 5;
Arr ['P'] = 7;
Arr ['R'] = 9;
Arr ['s'] = 2;
Arr ['T'] = 3;
Arr ['U'] = 4;
Arr ['V'] = 5;
Arr ['W'] = 6;
Arr ['X'] = 7;
Arr ['y'] = 8;
Arr ['Z'] = 9;
Arr ['1'] = 1;
Arr ['2'] = 2;
Arr ['3'] = 3;
Arr ['4'] = 4;
Arr ['5'] = 5;
Arr ['6'] = 6;
Arr ['7'] = 7;
Arr ['8'] = 8;
Arr ['9'] = 9;
Arr ['0'] = 0;
Brr [1] = 8;
Brr [2] = 7;
Brr [3] = 6;
Brr [4] = 5;
Brr [5] = 4;
Brr [6] = 3;
Brr [7] = 2;
Brr [8] = 10;
Brr [9] = 0;
Brr [10] = 9;
Brr [11] = 8;
Brr [12] = 7;
Brr [13] = 6;
Brr [14] = 5;
Brr [15] = 4;
Brr [16] = 3;
Brr [17] = 2;
Function getCheckCode (sVIN)
{
Var sKYZF = "ABCDEFGHJKLMNPRSTUVWXYZ1234567890 ";
Var sJYW = '';
Var bl = false;
Var blKYZF = false;
If (sVIN. length = 17)
{
Var iJQS = 0, intTemp = 0;
Ht = Arr;
HtZM = Brr;
Try
{
For (var I = 0; I <sVIN. length; I ++)
{
If (sKYZF. indexOf (sVIN. substr (I, 1 ))! =-1)
{
BlKYZF = true;
IJQS = iJQS + parseInt (ht [sVIN. substr (I, 1)]) * parseInt (htZM [(I + 1)]);
}
Else
{
BlKYZF = false;
Break;
}
}
If (blKYZF)
{
IntTemp = iJQS % 11;
If (intTemp = 10)
{
SJYW = "X ";
}
Else
{
SJYW = intTemp. toString ();
}
If (sJYW = sVIN. substr (8, 1) bl = true;
}
Else
{
Bl = false;
}
}
Catch (err)
{
Bl = false;
}
}
Return bl;
}
Alert (getCheckCode ("WVGAB97PXCD010692 "));
</Script>