public static boolean validate18Idcard(String idcard){
if(idcard == null ) {
return false;
}
if(idcard.length()!=18) {
return false;
}
char [] id =idcard.toCharArray();
int i, sum, n;
for (sum = i = 0; i < 17; i++){
sum += ((1 << (17 - i)) % 11) * (id[i] - '0');
}
n = (12 - (sum % 11)) % 11;
if (n < 10) {
return (n == id[17] - '0');
} else {
return (id[17] == 'X');
}
}
原文地址:https://www.cnblogs.com/demingblog/p/8185401.html
时间: 2024-10-10 01:08:55