l1-016 查验身份证java
时间: 2023-11-13 13:55:40 浏览: 122
好的,针对您的问题,我可以提供以下Java代码来实现身份证号码的校验:
```java
public static boolean isIDNumberValid(String idNumber) {
if (idNumber == null || idNumber.length() != 18) {
return false;
}
char[] chars = idNumber.toCharArray();
int[] ints = new int[chars.length];
for (int i = 0; i < chars.length; i++) {
ints[i] = Integer.parseInt(chars[i] + ""); }
int[] weights = new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
int sum = 0;
for (int i = 0; i < weights.length; i++) {
sum += ints[i] * weights[i];
}
int mod = sum % 11;
String[] checkCodes = new String[]{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
String checkCode = checkCodes[mod];
return checkCode.equals(chars[17] + "");
}
```
阅读全文