vin码校验规则请直接百度,
目前各论坛只有后台的vin码验证代码,没有前端验证代码;
所以:----上才艺 ↓
前端vin码校验代码
function vinCheck (vin){
if(vin.length!=17){
alert('vin位数错误')
return false
}
let mapObj = {
A:1,
B:2,
C:3,
D:4,
E:5,
F:6,
G: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,
}
let reg = /^[A-Za-z0-9]+$/;
if(reg.test(vin)){
let upCasrVin = vin.toUpperCase();
if(upCasrVin.indexOf('I')>=0||upCasrVin.indexOf('O')>=0||upCasrVin.indexOf('Q')>=0){
alert('vin码不能含有"I","O","Q";')
return false
}else{
let arr = vin.split("");
arr.forEach((element , index) => {
for(let ltem in mapObj){
if(element == ltem){
arr[index] = mapObj[ltem]
}
}
});
let weightedArr = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2]
let num = 0;
let newArr = [];
arr.forEach((element , index) => {
newArr.push(Number(arr[index])*Number(weightedArr[index]))
})
newArr.forEach(element=>{
num+=element
})
let checkNum = num%11
if(checkNum==10){
checkNum='X'
}
let distinguishNum = vin.toUpperCase().substring(8,9);
if(checkNum==distinguishNum){
alert('vin码验证通过')
return true;
}
alert('vin码验证不通过,校验码和识别码不一致')
return false;
}
}else{
alert('vin只能输入数字或者英文')
return false;
}
}
转发请注明出处,谢谢!