-
身份证有效性校验
-
从身份证号码中获取性别
-
从身份证号码中获取出生日期
-
15位身份证号码转换为18位
-
获取身份证校验码
-
校验身份证是否合法
-
获取年龄
-
public class IdCardManageUtil { private IdCardManageUtil() { } private final static int[] WEIGHT = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1}; /** * 校验码 */ private final static String[] VERIFYCODE = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}; private final static String ERRORMESSAGE = "身份证无效!"; /** * 判断身份证号码有效性 * * @param idCard 身份证号码 * @return 校验结果 0表示无效,1表示有效 */ public static Resp checkIdCard(String idCard) { String newIdCard = idCard; if (idCard.length() != 15 && idCard.length() != 18) { return Resp.fail("身份证位数必须是15位或者18位!"); } else { // 如果是15位,转换为18位 if (idCard.length() == 15) { Long m = Long.parseLong(idCard.substring(8, 10)); Long d = Long.parseLong(idCard.substring(10, 12)); if (m > 12 || d > 31) { return Resp.fail(ERRORMESSAGE); } else { n
身份证校验工具类
于 2022-05-20 17:58:10 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)