
io.afu.utils.string.IdcardUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils Show documentation
Show all versions of utils Show documentation
RffanLAB Utils For Many Way use
package io.afu.utils.string;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 中国身份证号码助手
*/
public class IdcardUtils {
/**
* 18位身份证号识别助手,通过正则来的,该方法适用于中华人民共和95年起的方法,如果有所改变,需要自行修改。
* @param idcard
* @return
*/
public static Boolean checkIfIsChineseIdcard(String idcard){
int length = idcard.length();
if (length == 15){
}
if (length ==18){
String patten = "^(11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|51|52|52|54|50|61|62|63|64|65|71|81|82)\\d{4}([1-3][0-9])\\d{9}[\\d|X|x]$";
Pattern p = Pattern.compile(patten);
Matcher m = p.matcher(idcard);
if (m.find()){
System.out.println("idcard = [" + m.group() + "]");
return true;
}
}
return false;
}
public static String getBirthFromIdcard(String idcard){
if (checkIfIsChineseIdcard(idcard)){
return idcard.substring(6,14);
}
return null;
}
public static void main(String[] args){
Boolean stat = checkIfIsChineseIdcard("");
System.out.println("args = [" + stat + "]");
System.out.println("args = [" + getBirthFromIdcard("") + "]");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
try {
Date newDate = simpleDateFormat.parse("");
System.out.println(simpleDateFormat.format(newDate));
}catch (Exception e){
e.printStackTrace();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy