All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.xiaoyuge5201.other.VerifyIDCard Maven / Gradle / Ivy

There is a newer version: 1.3.5
Show newest version
package com.github.xiaoyuge5201.other;

/**
 * 身份证验证
 *
 * @author xiaoyuge
 */
public class VerifyIDCard {
    /**
     * 驗證身份证是否合法
     * @param id 身份证
     * @return 结果
     */
    public static char doVerify(String id) {
        char pszSrc[] = id.toCharArray();
        int iS = 0;
        int iW[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
        char szVerCode[] = new char[]{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
        int i;
        for (i = 0; i < 17; i++) {
            iS += (int) (pszSrc[i] - '0') * iW[i];
        }
        int iY = iS % 11;
        return szVerCode[iY];
    }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy