车辆识别号(VIN)验证

//车辆识别号VIN中字母对应的数值
    @SuppressWarnings({ "unchecked", "rawtypes" })
public static Hashtable htbVIN(){
        Hashtable ht = new Hashtable();
        ht.put("A", 1);
        ht.put("B", 2);
        ht.put("C", 3);
        ht.put("D", 4);
        ht.put("E", 5);
        ht.put("F", 6);
        ht.put("G", 7);
        ht.put("H", 8);
        
        ht.put("J", 1);
        ht.put("K", 2);
        ht.put("L", 3);
        ht.put("M", 4);
        ht.put("N", 5);
        ht.put("P", 7);
        ht.put("R", 9);
        ht.put("S", 2);
        ht.put("T", 3);
        ht.put("U", 4);
        ht.put("V", 5);
        ht.put("W", 6);
        ht.put("X", 7);
        ht.put("Y", 8);
        ht.put("Z", 9);
        
        ht.put("1", 1);
        ht.put("2", 2);
        ht.put("3", 3);
        ht.put("4", 4);
        ht.put("5", 5);
        ht.put("6", 6);
        ht.put("7", 7);
        ht.put("8", 8);
        ht.put("9", 9);
        ht.put("0", 0);


        return ht;
    }




    //车辆识别号中顺序对应的加权系数
    @SuppressWarnings({ "rawtypes", "unchecked" })
public static Hashtable htbVIN_JQS(){
        Hashtable ht = new Hashtable();
        ht.put(1, 8);
        ht.put(2, 7);
        ht.put(3, 6);
        ht.put(4, 5);
        ht.put(5, 4);
        ht.put(6, 3);
        ht.put(7, 2);
        ht.put(8, 10);
        ht.put(9, 0);
        ht.put(10, 9);
        ht.put(11, 8);
        ht.put(12, 7);
        ht.put(13, 6);
        ht.put(14, 5);
        ht.put(15, 4);
        ht.put(16, 3);
        ht.put(17, 2);
        
        return ht;
    }


    // IN可用字符
    public static String  sKYZF="ABCDEFGHJKLMNPRSTUVWXYZ1234567890";
    
    //检验车辆识别号
    @SuppressWarnings("rawtypes")
public static boolean getCheckCode_VIN(String sVIN){
    String sJYW = "";
    boolean bl = false;
    boolean blKYZF = false;
        if (sVIN.length() == 17){
            int iJQS=0 ,intTemp=0;
            Hashtable ht = new Hashtable();
            ht = htbVIN();
            Hashtable htZM = new Hashtable();
            htZM = htbVIN_JQS();
            if(!sVIN.startsWith("L")){
            bl = false;
            }
            try{
                for (int i = 0; i < sVIN.length(); i++){
                    if (sKYZF.contains (sVIN.substring(i, i+1))){
                        blKYZF = true;
                        int temp1 = (int)ht.get(sVIN.substring(i, i+1));
                        int temp2 = (int)htZM.get(i+1);
                        iJQS = iJQS + temp1 * temp2;
                    }else{
                        blKYZF = false;
                        break;//发现不合法字符,直接退出循环                            
                    }
                }
                if (blKYZF){
                    intTemp = iJQS % 11;
                    if (intTemp == 10)
                        sJYW = "X";
                    else
                        sJYW = intTemp+"";
                    String temp = sVIN.charAt(8)+"";
                    if (sJYW.equals(temp))
                        bl = true;
                }else{
                    bl = false;
                }
            }catch(Exception e){
                bl = false;
            }
        }
        return bl;
    } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值