Commit 0d046be0 authored by yanzg's avatar yanzg

身份证识别

parent 7c784fb4
......@@ -24,12 +24,25 @@ public class SfzHandle18 implements SfzHandle {
@Override
public boolean validate(String idCard) {
if (idCard.length() == CHINA_ID_MAX_LENGTH && !idCard.startsWith(SfzHandleEn2023.START)) {
return validate18(idCard);
}
return false;
}
/**
* 验证身份证校验是否合法
*
* @param idCard 身份证
* @return 校验合法
*/
public static boolean validate18(String idCard) {
boolean bTrue = false;
if (idCard.length() == CHINA_ID_MAX_LENGTH) {
int endIndex = idCard.length() - 1;
// 前17位
String code17 = idCard.substring(0, 17);
String code17 = idCard.substring(0, endIndex);
// 第18位
String code18 = idCard.substring(17, CHINA_ID_MAX_LENGTH);
String code18 = idCard.substring(endIndex);
if (SfzHandleUtil.isNum(code17)) {
char[] cArr = code17.toCharArray();
if (cArr != null) {
......@@ -42,7 +55,6 @@ public class SfzHandle18 implements SfzHandle {
}
}
}
}
return bTrue;
}
......
package com.yanzuoguang.util.sfz;
import static com.yanzuoguang.util.sfz.SfzHandle15.CHINA_ID_MIN_LENGTH;
import static com.yanzuoguang.util.sfz.SfzHandle18.CHINA_ID_MAX_LENGTH;
import static com.yanzuoguang.util.sfz.SfzHandleUtil.cityCodes;
/**
* 2023年国外永居证处理
*
* @author 颜佐光
*/
public class SfzHandleEn2023 implements SfzHandle {
public static final String START = "9";
@Override
public boolean validate(String idCard) {
if (idCard.length() == CHINA_ID_MAX_LENGTH && idCard.startsWith(SfzHandleEn2023.START)) {
return SfzHandle18.validate18(idCard);
}
return false;
}
@Override
public String repair(String idCard) {
return null;
return idCard;
}
@Override
public String getGender(String idCard) {
return null;
return SfzHandleUtil.SFZ_HANDLE_18.getGender(idCard);
}
@Override
public String getBirthday(String idCard) {
return null;
return SfzHandleUtil.SFZ_HANDLE_18.getGender(idCard);
}
@Override
public String getCountry(String idCard) {
return null;
return idCard.substring(3, 6);
}
@Override
public String getAreaId(String idCard) {
return null;
return idCard.substring(1, 3);
}
@Override
public String getProvinceName(String idCard) {
return null;
int len = idCard.length();
String sProvince = null;
String sProvinNum = "";
if (len == CHINA_ID_MIN_LENGTH || len == CHINA_ID_MAX_LENGTH) {
sProvinNum = idCard.substring(1, 3);
}
sProvince = cityCodes.get(sProvinNum);
return sProvince;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment