如何识别身份证上的信息(根据身份证获取信息的方法)

发布日期:2024-05-14 01:15:08     作者:安抚人心     手机:https://m.xinb2b.cn/know/apa423211.html     违规举报

package com.hzrc.acl.authentication.security.util;import java.util.Calendar;public class getInfoByIdentityCodeUtil { private static boolean getValidIdentityCard(String identityCard){ if(identityCard == null || identityCard.length() == 0) return false; if(identityCard.length() != 18) return false; char[] identities = identityCard.toCharArray(); int code = 0; int[] number = new int[]{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1}; char[] numberArray = new char[]{'1','0','X','9','8','7','6','5','4','3','2'}; for(int i =0 ; i < 17; i ) { if(identities[i] < '0' || identities[i] > '9') { return false; } code = (identities[i] -'0') * number[i]; } code = code % 11; if(numberArray[code] != identities[17]) { return false; } return true; } public static Integer getGender(String identityCode) { if(identityCode == null || identityCode.length() == 0) return 0; int gender = 0; if(identityCode.length() == 18){ //如果身份证号18位,取身份证号倒数第二位 char c = identityCode.charAt(identityCode.length() - 2); gender = Integer.parseInt(String.valueOf(c)); }else{ //如果身份证号15位,取身份证号最后一位 char c = identityCode.charAt(identityCode.length() - 1); gender = Integer.parseInt(String.valueOf(c)); } if(gender % 2 == 1) return 1; return 2; } public static String getBirthday(String identityCode) { String birthday = null; if(identityCode == null || identityCode.length() == 0) return birthday; if (identityCode.length() == 15) { birthday = "19" identityCode.substring(6, 8) "-" identityCode.substring(8, 10) "-" identityCode.substring(10, 12); } else if (identityCode.length() == 18) { birthday = identityCode.substring(6, 10) "-" identityCode.substring(10, 12) "-" identityCode.substring(12, 14); } return birthday; } public static Integer getAge(String identityCode) { int age = 0; if(identityCode == null || identityCode.length() == 0) return age; int year = Calendar.getInstance().get(Calendar.YEAR); if (identityCode.length() == 15) { age = (year - Integer.parseInt("19" identityCode.substring(6, 8))); } else if (identityCode.length() == 18) { age = (year - Integer.parseInt(identityCode.substring(6, 10))); } return age; } public static String getNaticePlace(String identityCode) { if(identityCode == null || identityCode.length() == 0) return null; int nativePlaceCode=Integer.parseInt(identityCode.substring(0, 6)); return NativePlace.getNativePlace(nativePlaceCode); } public static void main(String[] args) { }}

获取籍贯,因为所有地区信息太多了,就不放在这里了,需要的可以评论,私发给你。

如何识别身份证上的信息(根据身份证获取信息的方法)(1)

知是行之始,行是知之成。

 
 
本文地址:https://www.xinb2b.cn/know/apa423211.html,转载请注明出处。

推荐图文
推荐经验知识
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  违规举报  |  蜀ICP备18010318号-4  |  SiteMaps  |  BaiDuNews
Processed in 0.025 second(s), 6 queries, Memory 0.53 M