java身份证号码校验规则 (源码)

身份证号码基础验证工具类

/**
 * Copyright (C), 2019-2019, XXXXXXX
 * FileName: IdentityDocumentUtil
 * Author:   Admin
 * Date:     2019/10/14 11:53
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.example.demo.Controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Admin
 * @create 2019/10/14
 * @since 1.0.0
 */
public class IdentityDocumentUtil {
   

        /** 中国公民身份证号码最小长度。 */
        private static final int CHINA_ID_MIN_LENGTH = 15;

        /** 中国公民身份证号码最大长度。 */
        private static final int CHINA_ID_MAX_LENGTH = 18;

        /** 省、直辖市代码表 */
        private static final String cityCode[] = {
   
                "11", "12", "13", "14", "15", "21", "22", "23", "31", "32", "33", "34", "35", "36", "37", "41",
                "42", "43", "44", "45", "46", "50", "51", "52", "53", "54", "61", "62", "63", "64", "65", "71",
                "81", "82", "91"
        };

        /** 每位加权因子 */
        private static final int power[] = {
   
                7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2
        };

        /** 第18位校检码 */
        private static final String verifyCode[] = {
   
                "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"
        };
        /** 最低年限 */
        private static final int MIN = 1930;
        private static Map<String, String> cityCodes = new HashMap<String, String>();
        /** 台湾身份首字母对应数字 */
        private static Map<String, Integer> twFirstCode = new HashMap<String, Integer>();
        /** 香港身份首字母对应数字 */
        private static Map<String, Integer> hkFirstCode = new HashMap<String, Integer>();
        static {
   
            cityCodes.put("11", "北京");
            cityCodes.put("12", "天津");
            cityCodes.put("13", "河北");
            cityCodes.put("14", "山西");
            cityCodes.put("15", "内蒙古");
            cityCodes.put("21", "辽宁");
            cityCodes.put("22", "吉林");
            cityCodes.put("23", "黑龙江");
            cityCodes.put("31", "上海");
            cityCodes.put("32", "江苏");
            cityCodes.put("33", "浙江");
            cityCodes.put("34", "安徽");
            cityCodes.put("35", "福建");
            cityCodes.put("36", "江西");
            cityCodes.put("37", "山东");
            cityCodes.put("41", "河南");
            cityCodes.put("42", "湖北");
            cityCodes.put("43", "湖南");
            cityCodes.put("44", "广东");
            cityCodes.put("45", "广西");
            cityCodes.put("46", "海南");
            cityCodes.put("50", "重庆");
            cityCodes.put("51", "四川");
            cityCodes.put("52", "贵州");
            cityCodes.put("53", "云南");
            cityCodes.put("54", "西藏");
            cityCodes.put("61", "陕西");
            cityCodes.put("62", "甘肃");
            cityCodes.put("63", "青海");
            cityCodes.put("64", "宁夏");
            cityCodes.put("65", "新疆");
            cityCodes.put("71", "台湾");
            cityCodes.put("81", "香港");
            cityCodes.put("82", "澳门");
            cityCodes.put("91", "国外");
            twFirstCode.put("A", 10);
            twFirstCode.put("B"
  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值