您现在的位置是:首页 > 前端 > 网站首页前端
废话不多说直接上代码
//车架号验证 vin
var onblurjs = function(vin){
if(vin.length>0 && vin.length!=17){
return false;
}else{
var vinVal = vin.toUpperCase();
//document.getElementById("vin_"+k).value = vinVal;
var charToNum = {'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};
var obj = 0;
var arr = new Array();
for (var i = 0 ; i < vinVal.length; i++) {
var temp = vinVal.charAt(i);
if(charToNum[temp]){
arr[i] = charToNum[temp];
}else{
arr[i] = Number(temp);
}
if(i==8){
arr[i] = vinVal.charAt(i);
}
};
var a1 = 8;
for (var i = 0; i < 7; i++) {
obj += Number(arr[i]) * a1 ;
a1--;
};
obj += Number(arr[7])*10;
var a2 = 9;
for (var i = 9; i < 17; i++) {
obj += Number(arr[i]) * a2;
a2--;
};
var result = Number(obj)%11;
if(parseInt(result) === 10){
result = 'X';
}
if(result == arr[8]){
//成功
return true;
}else{
//失败
return false;
}
}
};