// 身份证号校验 lenian 2018 07 02
public static final Boolean checkIdCard(String idCard) {
// 检测身份证是否包含中文
Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]");
Matcher aMatcher = pattern.matcher(idCard);
boolean isZH = aMatcher.find();
// 检测身份证位数是否是正常是法定位数(15,17,18)
boolean amount = (idCard.length() == 15 || idCard.length() == 17 || idCard.length() == 18);
// 两方面条件都满足时,返回true
boolean existed = (isZH == false) && (amount == true);
return existed;
}
JAVA后台实现对身份证号的校验(自主封装)
最新推荐文章于 2023-05-23 14:30:30 发布