教你身份证号查个人信息(方法基本都在这里了)
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1416119137658217"
crossorigin="anonymous"></script>
<ins class="adsbygoogle"
style="display:block"
data-ad-format="fluid"
data-ad-layout-key="-ef+6k-30-ac+ty"
data-ad-client="ca-pub-1416119137658217"
data-ad-slot="9398439682"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<pre class="syl-page-code hljs java" style="box-sizing: border-box; font-family: Monaco; font-size: 18px; margin-top: 20px; margin-bottom: 20px; padding: 15px; border: 0px; background-color: rgb(250, 250, 250); white-space: pre-wrap; word-break: break-all; overflow-x: auto; border-radius: 3px; color: rgb(34, 34, 34); box-shadow: rgba(216, 216, 216, 0.5) 0px 0px 0px 1px inset;">package com.hzrc.acl.authentication.security.util;import java.util.Calendar;/**
* 根据身份证号获取相关信息
*/public class getInfoByIdentityCodeUtil { /**
* 校验身份证的正确性
* @param identityCard
* @return
*/
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 < '0' || identities > '9')
{ return false;
}
code += (identities -'0') * number;
}
code = code % 11; if(numberArray != identities)
{ return false;
} return true;
} /**
* 根据身份证号获取性别
* @param identityCode
* @return 0位置 1男生 2女生
*/
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;
} /**
* 根据身份证号获取出生年月
* @param identityCode
* @return
*/
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;
} /**
* 根据身份证号获取年龄
* @param identityCode
* @return
*/
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;
} /**
* 根据身份证号获取籍贯
* @param identityCode
* @return
*/
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) {
}
}</pre><blockquote class="pgc-blockquote-abstract" style="box-sizing: border-box; margin: 20px 0px; padding: 16px 20px; border: none; quotes: none; position: relative; text-align: justify; color: rgb(80, 80, 80); background: rgb(244, 245, 246); font-size: 18px; line-height: 1.64; border-radius: 4px; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei%
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1416119137658217"
crossorigin="anonymous"></script>
<ins class="adsbygoogle"
style="display:block"
data-ad-format="autorelaxed"
data-ad-client="ca-pub-1416119137658217"
data-ad-slot="9866139705"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</br>微信搜索公众号【深圳家】或者直接搜索【i-shenzhen】,获取更多信息
页:
[1]