/**
* 修补15位居民身份证号码为18位
* @param personIDCode
* @return
*/
public static String sfz15to18(String personIDCode){
try{
Long.parseLong(personIDCode);
}
catch(Exception e){
return personIDCode;
}
if (personIDCode == null || personIDCode.trim().length() != 15) return personIDCode;
String id17 = personIDCode.substring(0, 6) + "19"+ personIDCode.substring(6, 15); // 15为身份证补\'19\'
char[] code = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' }; // 11个
int[] factor = { 0, 2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9, 7 }; // 18个;
int[] idcd = new int[18];
int i;
int j;
int sum;
int remainder;
for (i = 1; i < 18; i++){
j = 17 - i;
idcd[i] = Integer.parseInt(id17.substring(j, j + 1));
}
sum = 0;
for (i = 1; i < 18; i++){
sum = sum + idcd[i] * factor[i];
}
remainder = sum % 11;
String lastCheckBit = String.valueOf(code[remainder]);
return id17 + lastCheckBit;
}
修补居民身份证15-->18
最新推荐文章于 2024-11-13 20:43:20 发布