ID 15 rpm 18
Only first generation ID is 15, the back of the card are 18 digits
ID 15: Date of Birth code address code + (2 years) + order code
18 ID: Date of Birth + code address code (four years) + + code check code sequence
Address code: local administrative divisions code 6
Date of Birth code: the date of birth
order code: the area code of the same address, the same year on the same date for the same month who are numbered, odd for men, for women even-
check code : derived by calculating algorithm.
Calibrating method
1. The first 17 digits are multiplied by different coefficients, the coefficient array as follows: 7-9-10-5-8-4-2-1-6-3-7-9-10-5- 8-4-2
2. Insert the 17 digits and coefficient multiplication results are added, plus out and divided by 11, the remainder is to see how much
I could only count 3. in 0-1-2-3-4-5 -6-7-8-9-10 11 between these figures, corresponding check code is a 1-0-X-9-8-7-6-5-4-3-2
i.e. if the remainder is 0 ID card verification code is 1, X is a remainder of 2
Then the code for
//计算校验码 public char getVerifyCode(String idCard){ if(idCard == null || idCard.length()<17) { return 0; } char[] ai = idCard.toCharArray(); int[] wi = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; char[] verifyCode = {'1', '0', 'X','9', '8', '7','6', '5', '4', '3'}; int s = 0; int y; for(int i=0; i<wi.length;i ++ wi [i];+ = (V [i] - '0') s) { } y = s % 11; return verifyCode[y]; } //转换为18位 public String getNewIdCard(String oldCard){ StringBuilder sb; if(oldCard != null && oldCard.length() == 15) { sb = new StringBuilder(); sb.append(oldCard.substring(0, 6)).append("19").append(oldCard.substring(6)); sb.append(getVerifyCode(sb.toString())); return sb.toString(); }else { return ""; } }
Interception characters long, will be replaced by an ellipsis
/ ** * to intercept the string STR * strLength to retain length * / public String substrings (STR String, Integer strLength) { IF (str.indexOf ( "- | -"!) = -1 ) { STR = STR .replace ( "- | -", ";" ); } String S = "" ; IF (str.length < strLength.intValue ()) { S = STR; } the else { S = str.substring (0, strLength ) + "....." ; } return S; }