java身份證工具類(校驗身份證是否合法、通過身份證獲取年齡、性別、生日,將15位身份證轉爲18位等)

一、簡介

因爲工作需要經常用到身份證做一些相關操作,於是通過查閱資料總結出一些常用的工具方法,包括校驗身份證是否合法、通過身份證獲取年齡、通過身份證獲取性別、通過身份證獲取戶籍地址、通過身份證獲取生日、將15位身份證轉爲18位身份證等。

二、此工具類相關方法說明

  • static boolean isValidCard(String idCard)
    校驗身份證是否合法

  • static String convertIdCard(String idCard)
    將15位身份證號碼轉換爲18位

  • static Date getBirthDate(String idCard)
    從身份證號碼中獲取生日日期,只支持15或18位身份證號碼

  • static int getAgeByCard(String idCard)
    根據身份編號獲取年齡,只支持15或18位身份證號碼

  • static int getAge(Date birthDay, Date dateToCompare)
    根據出生日期計算在某個日期的年齡(birthDay 生日 dateToCompare 需要對比的日期)

  • static int getGender(String idCard)
    根據身份證號碼獲取性別,只支持15或18位身份證號碼(性別 1 : 男 , 0 : 女)

  • static Short getYearByIdCard(String idCard)
    根據身份證號碼獲取生日年,只支持15或18位身份證號碼

  • static Short getMonthByIdCard(String idCard)
    根據身份證號碼獲取生日月,只支持15或18位身份證號碼

  • static Short getDayByIdCard(String idCard)
    根據身份證號碼獲取生日天,只支持15或18位身份證號碼

  • static String getProvince(String idCard)
    根據身份證號碼獲取戶籍省份,只支持15或18位身份證號碼

  • static String getBirth(String idCard)
    根據身份編號獲取生日,只支持15或18位身份證號碼(返回一個yyyyMMdd格式的字符串,比如20200108)

  • static int year(Date date)
    根據日期獲取年

  • static boolean isBirthday(CharSequence value)
    驗證是否爲生日,只支持以下幾種格式:
    yyyyMMdd
    yyyy-MM-dd
    yyyy/MM/dd
    yyyy.MM.dd
    yyyy年MM月dd日

三、使用示例

        String idCard = "110101199003077897";
      
        //校驗身份證是否合法
        System.out.println(isValidCard(idCard));
      
        //通過身份證獲取年齡
        System.out.println(getAgeByCard(idCard));
       
        //通過身份證獲取戶籍省份
        System.out.println(getProvince(idCard));
       
        //通過身份證獲取生日日期
        System.out.println(getBirthDate(idCard));
       
        //通過身份證獲取性別
        System.out.println(getGender(idCard));

四、身份證工具類

package com.zjx.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 身份證相關工具類
 *
 * @author zhaojiaxing
 * @version 1.0
 * @since 2020/01/07 14:40
 */
public class IdCardUtil {

   /**
     * 是否有效身份證號
     *
     * @param idCard 身份證號,支持18位、15位和港澳臺的10位
     * @return 是否有效
     */
    public static boolean isValidCard(String idCard) {
        idCard = idCard.trim();
        int length = idCard.length();
        switch (length) {
            // 18位身份證
            case 18:
                return isValidCard18(idCard);
            // 15位身份證
            case 15:
                return isValidCard15(idCard);
            // 10位身份證,港澳臺地區
            case 10: {
                String[] cardval = isValidCard10(idCard);
                return null != cardval && cardval[2].equals("true");
            }
            default:
                return false;
        }
    }

    /**
     * 將15位身份證號碼轉換爲18位
     *
     * @param idCard 15位身份編碼
     * @return 18位身份編碼
     */
    public static String convertIdCard(String idCard) {
        StringBuilder idCard18;
        if (idCard.length() != CHINA_ID_MIN_LENGTH) {
            return null;
        }
        if (isMatch(NUMBERS, idCard)) {
            // 獲取出生年月日
            String birthday = idCard.substring(6, 12);
            Date birthDate = strToDate(birthday, YY_MM_DD);
            // 獲取出生年
            int sYear = year(birthDate);
            // 理論上2000年之後不存在15位身份證,可以不要此判斷
            if (sYear > 2000) {
                sYear -= 100;
            }
            idCard18 = new StringBuilder().append(idCard, 0, 6).append(sYear).append(idCard.substring(8));
            // 獲取校驗位
            char sVal = getCheckCode18(idCard18.toString());
            idCard18.append(sVal);
        } else {
            return null;
        }
        return idCard18.toString();
    }

    /**
     * 從身份證號碼中獲取生日日期,只支持15或18位身份證號碼
     *
     * @param idCard 身份證號碼
     * @return 日期
     */
    public static Date getBirthDate(String idCard) {
        final String birthByIdCard = getBirth(idCard);
        return null == birthByIdCard ? null : strToDate(birthByIdCard, YYYY_MM_DD);
    }

    /**
     * 根據身份編號獲取年齡,只支持15或18位身份證號碼
     *
     * @param idCard 身份證號
     * @return 年齡
     */
    public static int getAgeByCard(String idCard) {
        String birth = getBirth(idCard);
        return getAge(strToDate(birth, YYYY_MM_DD), new Date());
    }

    /**
     * 根據出生日期計算在某個日期的年齡
     *
     * @param birthDay      生日
     * @param dateToCompare 需要對比的日期
     * @return 年齡
     */
    public static int getAge(Date birthDay, Date dateToCompare) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateToCompare);

        if (cal.before(birthDay)) {
            throw new IllegalArgumentException("Birthday is after date " + dateToCompare + " !");
        }

        //先獲取指定日期的年月日
        final int year = cal.get(Calendar.YEAR);
        final int month = cal.get(Calendar.MONTH);
        final int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
        final boolean isLastDayOfMonth = dayOfMonth == cal.getActualMaximum(Calendar.DAY_OF_MONTH);

        //獲取出生日期的年月
        cal.setTime(birthDay);
        int age = year - cal.get(Calendar.YEAR);
        final int monthBirth = cal.get(Calendar.MONTH);

        if (month == monthBirth) {
            //獲取出生日期的日
            final int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
            final boolean isLastDayOfMonthBirth = dayOfMonthBirth == cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            // 如果生日在當月,但是未達到生日當天的日期,年齡減一(判斷是否是最後一天是爲了去除潤月的影響)
            if ((false == isLastDayOfMonth || false == isLastDayOfMonthBirth) && dayOfMonth < dayOfMonthBirth) {
                age--;
            }
        } else if (month < monthBirth) {
            // 如果當前月份未達到生日的月份,年齡計算減一
            age--;
        }

        return age;
    }


    /**
     * 根據身份證號碼獲取生日年,只支持15或18位身份證號碼
     *
     * @param idCard 身份編號
     * @return 生日(yyyy)
     */
    public static Short getYearByIdCard(String idCard) {
        final int len = idCard.length();
        if (len < CHINA_ID_MIN_LENGTH) {
            return null;
        } else if (len == CHINA_ID_MIN_LENGTH) {
            idCard = convertIdCard(idCard);
        }
        return Short.valueOf(idCard.substring(6, 10));
    }

    /**
     * 根據身份證號碼獲取生日月,只支持15或18位身份證號碼
     *
     * @param idCard 身份編號
     * @return 生日(MM)
     */
    public static Short getMonthByIdCard(String idCard) {
        final int len = idCard.length();
        if (len < CHINA_ID_MIN_LENGTH) {
            return null;
        } else if (len == CHINA_ID_MIN_LENGTH) {
            idCard = convertIdCard(idCard);
        }
        return Short.valueOf(idCard.substring(10, 12));
    }

    /**
     * 根據身份證號碼獲取生日天,只支持15或18位身份證號碼
     *
     * @param idCard 身份編號
     * @return 生日(dd)
     */
    public static Short getDayByIdCard(String idCard) {
        final int len = idCard.length();
        if (len < CHINA_ID_MIN_LENGTH) {
            return null;
        } else if (len == CHINA_ID_MIN_LENGTH) {
            idCard = convertIdCard(idCard);
        }
        return Short.valueOf(idCard.substring(12, 14));
    }

    /**
     * 根據身份證號碼獲取性別,只支持15或18位身份證號碼
     *
     * @param idCard 身份編號
     * @return 性別(1 : 男 , 0 : 女)
     */
    public static int getGender(String idCard) {
        if (idCard == null || idCard.trim().length() == 0) {
            throw new IllegalArgumentException("ID Card is must not null");
        }
        final int len = idCard.length();
        if (len < CHINA_ID_MIN_LENGTH) {
            throw new IllegalArgumentException("ID Card length must be 15 or 18");
        }

        if (len == CHINA_ID_MIN_LENGTH) {
            idCard = convertIdCard(idCard);
        }
        char sCardChar = idCard.charAt(16);
        return (sCardChar % 2 != 0) ? 1 : 0;
    }

    /**
     * 根據身份證號碼獲取戶籍省份,只支持15或18位身份證號碼
     *
     * @param idCard 身份編碼
     * @return 省級編碼。
     */
    public static String getProvince(String idCard) {
        int len = idCard.length();
        if (len == CHINA_ID_MIN_LENGTH || len == CHINA_ID_MAX_LENGTH) {
            String sProvinNum = idCard.substring(0, 2);
            return cityCodes.get(sProvinNum);
        }
        return null;
    }

    /**
     * 判斷18位身份證的合法性
     *
     * 公民身份號碼是特徵組合碼,由十七位數字本體碼和一位數字校驗碼組成,排列順序從左至右依次爲:六位數字地址碼,八位數字出生日期碼,三位數字順序碼和一位數字校驗碼。
     * 順序碼: 表示在同一地址碼所標識的區域範圍內,對同年、同月、同 日出生的人編定的順序號,順序碼的奇數分配給男性,偶數分配 給女性。
     * 第1、2位數字表示:所在省份的代碼;第3、4位數字表示:所在城市的代碼;第5、6位數字表示:所在區縣的代碼,第7~14位數字表示:出生年、月、日
     * 第15、16位數字表示:所在地的派出所的代碼;第17位數字表示性別:奇數表示男性,偶數表示女性
     * 第18位數字是校檢碼,用來檢驗身份證的正確性。校檢碼可以是0~9的數字,有時也用x表示
     * 第十八位數字(校驗碼)的計算方法爲:
     *
     * @param idCard 待驗證的身份證
     * @return 是否有效的18位身份證
     */
    private static boolean isValidCard18(String idCard) {
        if (CHINA_ID_MAX_LENGTH != idCard.length()) {
            return false;
        }

        //校驗生日
        if (false == isBirthday(idCard.substring(6, 14))) {
            return false;
        }

        // 前17位
        String code17 = idCard.substring(0, 17);
        // 第18位
        char code18 = Character.toLowerCase(idCard.charAt(17));
        if (isMatch(NUMBERS, code17)) {
            // 獲取校驗位
            char val = getCheckCode18(code17);
            return val == code18;
        }
        return false;
    }

    /**
     * 驗證15位身份編碼是否合法
     *
     * @param idCard 身份編碼
     * @return 是否合法
     */
    private static boolean isValidCard15(String idCard) {
        if (CHINA_ID_MIN_LENGTH != idCard.length()) {
            return false;
        }
        if (isMatch(NUMBERS, idCard)) {
            // 省份
            String proCode = idCard.substring(0, 2);
            if (null == cityCodes.get(proCode)) {
                return false;
            }

            //校驗生日(兩位年份,補充爲19XX)
            return false != isBirthday("19" + idCard.substring(6, 12));
        } else {
            return false;
        }
    }

    /**
     * 驗證10位身份編碼是否合法
     *
     * @param idCard 身份編碼
     * @return 身份證信息數組
     * [0] - 臺灣、澳門、香港 [1] - 性別(男M,女F,未知N) [2] - 是否合法(合法true,不合法false) 若不是身份證件號碼則返回null
     */
    private static String[] isValidCard10(String idCard) {
        if (idCard == null || idCard.trim().length() == 0) {
            return null;
        }
        String[] info = new String[3];
        String card = idCard.replaceAll("[()]", "");
        if (card.length() != 8 && card.length() != 9 && idCard.length() != 10) {
            return null;
        }
        // 臺灣
        if (idCard.matches("^[a-zA-Z][0-9]{9}$")) {
            info[0] = "臺灣";
            String char2 = idCard.substring(1, 2);
            if (char2.equals("1")) {
                info[1] = "M";
            } else if (char2.equals("2")) {
                info[1] = "F";
            } else {
                info[1] = "N";
                info[2] = "false";
                return info;
            }
            info[2] = isValidTWCard(idCard) ? "true" : "false";
        } else if (idCard.matches("^[157][0-9]{6}\\(?[0-9A-Z]\\)?$")) {
            // 澳門
            info[0] = "澳門";
            info[1] = "N";
        } else if (idCard.matches("^[A-Z]{1,2}[0-9]{6}\\(?[0-9A]\\)?$")) {
            // 香港
            info[0] = "香港";
            info[1] = "N";
            info[2] = isValidHKCard(idCard) ? "true" : "false";
        } else {
            return null;
        }
        return info;
    }

    /**
     * 驗證臺灣身份證號碼
     *
     * @param idCard 身份證號碼
     * @return 驗證碼是否符合
     */
    private static boolean isValidTWCard(String idCard) {
        if (idCard == null || idCard.trim().length() == 0) {
            return false;
        }
        String start = idCard.substring(0, 1);
        Integer iStart = twFirstCode.get(start);
        if (null == iStart) {
            return false;
        }
        String mid = idCard.substring(1, 9);
        String end = idCard.substring(9, 10);
        int sum = iStart / 10 + (iStart % 10) * 9;
        final char[] chars = mid.toCharArray();
        int iflag = 8;
        for (char c : chars) {
            sum += Integer.valueOf(String.valueOf(c)) * iflag;
            iflag--;
        }
        return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.valueOf(end);
    }

    /**
     * 驗證香港身份證號碼
     * 身份證前2位爲英文字符,如果只出現一個英文字符則表示第一位是空格,對應數字58 前2位英文字符A-Z分別對應數字10-35 最後一位校驗碼爲0-9的數字加上字符"A","A"代表10
     * 將身份證號碼全部轉換爲數字,分別對應乘9-1相加的總和,整除11則證件號碼有效
     * @param idCard 身份證號碼
     * @return 驗證碼是否符合
     */
    private static boolean isValidHKCard(String idCard) {
        String card = idCard.replaceAll("[()]", "");
        int sum;
        if (card.length() == 9) {
            sum = (Character.toUpperCase(card.charAt(0)) - 55) * 9 + (Character.toUpperCase(card.charAt(1)) - 55) * 8;
            card = card.substring(1, 9);
        } else {
            sum = 522 + (Character.toUpperCase(card.charAt(0)) - 55) * 8;
        }
        String start = idCard.substring(0, 1);
        Integer iStart = hkFirstCode.get(start);
        if (null == iStart) {
            return false;
        }
        String mid = card.substring(1, 7);
        String end = card.substring(7, 8);
        char[] chars = mid.toCharArray();
        int iflag = 7;
        for (char c : chars) {
            sum = sum + Integer.valueOf(String.valueOf(c)) * iflag;
            iflag--;
        }
        if ("A".equals(end.toUpperCase())) {
            sum += 10;
        } else {
            sum += Integer.parseInt(end);
        }
        return sum % 11 == 0;
    }

    /**
     * 根據身份編號獲取生日,只支持15或18位身份證號碼
     *
     * @param idCard 身份編號
     * @return 生日(yyyyMMdd)
     */
    public static String getBirth(String idCard) {
        final int len = idCard.length();
        if (len < CHINA_ID_MIN_LENGTH) {
            return null;
        } else if (len == CHINA_ID_MIN_LENGTH) {
            idCard = convertIdCard(idCard);
        }
        return idCard.substring(6, 14);
    }

    /**
     * 獲得18位身份證校驗碼
     * 計算方式:
     * 將前面的身份證號碼17位數分別乘以不同的係數。從第一位到第十七位的係數分別爲:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
     * 將這17位數字和係數相乘的結果相加
     * 用加出來和除以11,看餘數是多少
     * 餘數只可能有0 1 2 3 4 5 6 7 8 9 10這11個數字。其分別對應的最後一位身份證的號碼爲1 0 X 9 8 7 6 5 4 3 2
     * 通過上面得知如果餘數是2,就會在身份證的第18位數字上出現羅馬數字的Ⅹ。如果餘數是10,身份證的最後一位號碼就是2
     * @param code17 18位身份證號中的前17位
     * @return 第18位
     */
    private static char getCheckCode18(String code17) {
        int sum = getPowerSum(code17.toCharArray());
        return getCheckCode18(sum);
    }

    /**
     * 將power和值與11取模獲得餘數進行校驗碼判斷
     *
     * @param iSum 加權和
     * @return 校驗位
     */
    private static char getCheckCode18(int iSum) {
        switch (iSum % 11) {
            case 10:
                return '2';
            case 9:
                return '3';
            case 8:
                return '4';
            case 7:
                return '5';
            case 6:
                return '6';
            case 5:
                return '7';
            case 4:
                return '8';
            case 3:
                return '9';
            case 2:
                return 'x';
            case 1:
                return '0';
            case 0:
                return '1';
            default:
                return SPACE;
        }
    }

    /**
     * 將身份證的每位和對應位的加權因子相乘之後,再得到和值
     *
     * @param iArr 身份證號碼的數組
     * @return 身份證編碼
     */
    private static int getPowerSum(char[] iArr) {
        int iSum = 0;
        if (power.length == iArr.length) {
            for (int i = 0; i < iArr.length; i++) {
                iSum += Integer.valueOf(String.valueOf(iArr[i])) * power[i];
            }
        }
        return iSum;
    }

    /**
     * 根據日期獲取年
     *
     * @param date 日期
     * @return 年的部分
     */
    public static int year(Date date) {
        Calendar ca = Calendar.getInstance();
        ca.setTime(date);
        return ca.get(Calendar.YEAR);
    }

    /**
     * 驗證是否爲生日<br>
     * 只支持以下幾種格式:
     * <ul>
     * <li>yyyyMMdd</li>
     * <li>yyyy-MM-dd</li>
     * <li>yyyy/MM/dd</li>
     * <li>yyyy.MM.dd</li>
     * <li>yyyy年MM月dd日</li>
     * </ul>
     *
     * @param value 值
     * @return 是否爲生日
     */
    public static boolean isBirthday(CharSequence value) {
        if (isMatch(BIRTHDAY, value)) {
            Matcher matcher = BIRTHDAY.matcher(value);
            if (matcher.find()) {
                int year = Integer.parseInt(matcher.group(1));
                int month = Integer.parseInt(matcher.group(3));
                int day = Integer.parseInt(matcher.group(5));
                return isBirthday(year, month, day);
            }
        }
        return false;
    }

    /**
     * 驗證是否爲生日
     *
     * @param year  年,從1900年開始計算
     * @param month 月,從1開始計數
     * @param day   日,從1開始計數
     * @return 是否爲生日
     */
    public static boolean isBirthday(int year, int month, int day) {
        // 驗證年
        int thisYear = year(new Date());
        if (year < 1900 || year > thisYear) {
            return false;
        }

        // 驗證月
        if (month < 1 || month > 12) {
            return false;
        }

        // 驗證日
        if (day < 1 || day > 31) {
            return false;
        }
        // 檢查幾個特殊月的最大天數
        if (day == 31 && (month == 4 || month == 6 || month == 9 || month == 11)) {
            return false;
        }
        if (month == 2) {
            // 在2月,非閏年最大28,閏年最大29
            return day < 29 || (day == 29 && isLeapYear(year));
        }
        return true;
    }

    /**
     * 是否閏年
     *
     * @param year 年
     * @return 是否閏年
     */
    private static boolean isLeapYear(int year) {
        return new GregorianCalendar().isLeapYear(year);
    }

    /**
     * 將字符串轉換成指定格式的日期
     *
     * @param str        日期字符串.
     * @param dateFormat 日期格式. 如果爲空,默認爲:yyyy-MM-dd HH:mm:ss.
     * @return
     */
    private static Date strToDate(final String str, String dateFormat) {
        if (str == null || str.trim().length() == 0) {
            return null;
        }
        try {
            if (dateFormat == null || dateFormat.length() == 0) {
                dateFormat = DATE_FORMAT;
            }
            DateFormat fmt = new SimpleDateFormat(dateFormat);
            return fmt.parse(str.trim());
        } catch (Exception ex) {
            return null;
        }
    }

    /**
     * 給定內容是否匹配正則
     *
     * @param pattern 模式
     * @param content 內容
     * @return 正則爲null或者""則不檢查,返回true,內容爲null返回false
     */
    private static boolean isMatch(Pattern pattern, CharSequence content) {
        if (content == null || pattern == null) {
            // 提供null的字符串爲不匹配
            return false;
        }
        return pattern.matcher(content).matches();
    }


    /**
     * 中國公民身份證號碼最小長度。
     */
    private static final int CHINA_ID_MIN_LENGTH = 15;
    /**
     * 中國公民身份證號碼最大長度。
     */
    private static final int CHINA_ID_MAX_LENGTH = 18;
    /**
     * 每位加權因子
     */
    private static final int[] power = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};

    /**
     * 省市代碼表
     */
    private static Map<String, String> cityCodes = new HashMap<>();
    /**
     * 臺灣身份首字母對應數字
     */
    private static Map<String, Integer> twFirstCode = new HashMap<>();
    /**
     * 香港身份首字母對應數字
     */
    private static Map<String, Integer> hkFirstCode = new HashMap<>();

    /**
     * 默認日期模板
     */
    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    private static final String YYYY_MM_DD = "yyyyMMdd";
    private static final String YY_MM_DD = "yyMMdd";
    public static final char SPACE = ' ';
    /**
     * 數字
     */
    public final static Pattern NUMBERS = Pattern.compile("\\d+");
    /**
     * 生日
     */
    public final static Pattern BIRTHDAY = Pattern.compile("^(\\d{2,4})([/\\-.年]?)(\\d{1,2})([/\\-.月]?)(\\d{1,2})日?$");

    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", 11);
        twFirstCode.put("C", 12);
        twFirstCode.put("D", 13);
        twFirstCode.put("E", 14);
        twFirstCode.put("F", 15);
        twFirstCode.put("G", 16);
        twFirstCode.put("H", 17);
        twFirstCode.put("J", 18);
        twFirstCode.put("K", 19);
        twFirstCode.put("L", 20);
        twFirstCode.put("M", 21);
        twFirstCode.put("N", 22);
        twFirstCode.put("P", 23);
        twFirstCode.put("Q", 24);
        twFirstCode.put("R", 25);
        twFirstCode.put("S", 26);
        twFirstCode.put("T", 27);
        twFirstCode.put("U", 28);
        twFirstCode.put("V", 29);
        twFirstCode.put("X", 30);
        twFirstCode.put("Y", 31);
        twFirstCode.put("W", 32);
        twFirstCode.put("Z", 33);
        twFirstCode.put("I", 34);
        twFirstCode.put("O", 35);

        //來自http://shenfenzheng.bajiu.cn/?rid=40
        // 持證人擁有香港居留權
        hkFirstCode.put("A", 1);
        // 持證人所報稱的出生日期或地點自首次登記以後,曾作出更改
        hkFirstCode.put("B", 2);
        // 持證人登記領證時在香港的居留受到入境事務處處長的限制
        hkFirstCode.put("C", 3);
        // 持證人所報的姓名自首次登記以後,曾作出更改
        hkFirstCode.put("N", 14);
        // 持證人報稱在香港、澳門及中國以外其他地區或國家出生
        hkFirstCode.put("O", 15);
        // 持證人擁有香港入境權
        hkFirstCode.put("R", 18);
        // 持證人登記領證時在香港的居留不受入境事務處處長的限制
        hkFirstCode.put("U", 21);
        // 持證人報稱在澳門地區出生
        hkFirstCode.put("W", 23);
        // 持證人報稱在中國大陸出生
        hkFirstCode.put("X", 24);
        // 持證人報稱在香港出生
        hkFirstCode.put("Z", 26);
    }

}

發佈了94 篇原創文章 · 獲贊 94 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章