@Test public void testValidateHKCard() throws Exception { }
public static boolean validateHKCard(String idCard) { String card = idCard.replaceAll("[\\(|\\)]", ""); Integer sum; if (card.length() == 9) { sum = ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 9 + ((int) card.substring(1, 2).toUpperCase().toCharArray()[0] - 55) * 8; card = card.substring(1, 9); } else { sum = 522 + ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 8; } String mid = card.substring(1, 7); String end = card.substring(7, 8); char[] chars = mid.toCharArray(); Integer iflag = 7; for (char c : chars) { sum = sum + Integer.valueOf(c + "") * iflag; iflag--; } if (end.toUpperCase().equals("A")) { sum = sum + 10; } else { sum = sum + Integer.valueOf(end); } return (sum % 11 == 0); }
IdCardKit { public static boolean validateHKCard(String idCard) { String card = idCard.replaceAll("[\\(|\\)]", ""); Integer sum; if (card.length() == 9) { sum = ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 9 + ((int) card.substring(1, 2).toUpperCase().toCharArray()[0] - 55) * 8; card = card.substring(1, 9); } else { sum = 522 + ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 8; } String mid = card.substring(1, 7); String end = card.substring(7, 8); char[] chars = mid.toCharArray(); Integer iflag = 7; for (char c : chars) { sum = sum + Integer.valueOf(c + "") * iflag; iflag--; } if (end.toUpperCase().equals("A")) { sum = sum + 10; } else { sum = sum + Integer.valueOf(end); } return (sum % 11 == 0); } }
IdCardKit { public static boolean validateHKCard(String idCard) { String card = idCard.replaceAll("[\\(|\\)]", ""); Integer sum; if (card.length() == 9) { sum = ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 9 + ((int) card.substring(1, 2).toUpperCase().toCharArray()[0] - 55) * 8; card = card.substring(1, 9); } else { sum = 522 + ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 8; } String mid = card.substring(1, 7); String end = card.substring(7, 8); char[] chars = mid.toCharArray(); Integer iflag = 7; for (char c : chars) { sum = sum + Integer.valueOf(c + "") * iflag; iflag--; } if (end.toUpperCase().equals("A")) { sum = sum + 10; } else { sum = sum + Integer.valueOf(end); } return (sum % 11 == 0); }  }
IdCardKit { public static boolean validateHKCard(String idCard) { String card = idCard.replaceAll("[\\(|\\)]", ""); Integer sum; if (card.length() == 9) { sum = ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 9 + ((int) card.substring(1, 2).toUpperCase().toCharArray()[0] - 55) * 8; card = card.substring(1, 9); } else { sum = 522 + ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 8; } String mid = card.substring(1, 7); String end = card.substring(7, 8); char[] chars = mid.toCharArray(); Integer iflag = 7; for (char c : chars) { sum = sum + Integer.valueOf(c + "") * iflag; iflag--; } if (end.toUpperCase().equals("A")) { sum = sum + 10; } else { sum = sum + Integer.valueOf(end); } return (sum % 11 == 0); }  static String conver15CardTo18(String idCard); static boolean validateCard(String idCard); static boolean validateIdCard18(String idCard); static boolean validateIdCard15(String idCard); static String[] validateIdCard10(String idCard); static boolean validateTWCard(String idCard); static boolean validateHKCard(String idCard); static int[] converCharToInt(char[] ca); static int getPowerSum(int[] iArr); static String getCheckCode18(int iSum); static int getAgeByIdCard(String idCard); static String getBirthByIdCard(String idCard); static Short getYearByIdCard(String idCard); static Short getMonthByIdCard(String idCard); static Short getDateByIdCard(String idCard); static String getGenderByIdCard(String idCard); static String getProvinceByIdCard(String idCard); }
IdCardKit { public static boolean validateHKCard(String idCard) { String card = idCard.replaceAll("[\\(|\\)]", ""); Integer sum; if (card.length() == 9) { sum = ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 9 + ((int) card.substring(1, 2).toUpperCase().toCharArray()[0] - 55) * 8; card = card.substring(1, 9); } else { sum = 522 + ((int) card.substring(0, 1).toUpperCase().toCharArray()[0] - 55) * 8; } String mid = card.substring(1, 7); String end = card.substring(7, 8); char[] chars = mid.toCharArray(); Integer iflag = 7; for (char c : chars) { sum = sum + Integer.valueOf(c + "") * iflag; iflag--; } if (end.toUpperCase().equals("A")) { sum = sum + 10; } else { sum = sum + Integer.valueOf(end); } return (sum % 11 == 0); }  static String conver15CardTo18(String idCard); static boolean validateCard(String idCard); static boolean validateIdCard18(String idCard); static boolean validateIdCard15(String idCard); static String[] validateIdCard10(String idCard); static boolean validateTWCard(String idCard); static boolean validateHKCard(String idCard); static int[] converCharToInt(char[] ca); static int getPowerSum(int[] iArr); static String getCheckCode18(int iSum); static int getAgeByIdCard(String idCard); static String getBirthByIdCard(String idCard); static Short getYearByIdCard(String idCard); static Short getMonthByIdCard(String idCard); static Short getDateByIdCard(String idCard); static String getGenderByIdCard(String idCard); static String getProvinceByIdCard(String idCard); static final int CHINA_ID_MIN_LENGTH; static final int CHINA_ID_MAX_LENGTH; static final String cityCode; static final int power; static final String verifyCode; static final int MIN; static final Map<String, String> cityCodes; static final Map<String, Integer> twFirstCode; static final Map<String, Integer> hkFirstCode; }