ImportJava.util.Calendar; Public classCertnoutil { Public Static BooleanVidnumbyregex (String idnum) {string Curyear= "" +calendar.getinstance (). get (Calendar.year); intY3 = Integer.valueof (curyear.substring (2, 3)); intY4 = Integer.valueof (curyear.substring (3, 4)); //0103 1973 0 9 051 9 returnIdnum.matches ("^ (1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5]|71|8[1-2]) \\d{4} (19\\d{2}|20 ([0-" + (y3-1) + "][0-9]|" + Y3 + "[0-" +Y4+ "])) (((0[1-9]|1[0-2)) (0[1-9]|[ 1-2][0-9]|3[0-1])) \\d{3} ([0-9]|x| X) $ "); //1825 1988 0 7 1 3 003 4 } Private Static intId_length = 17; Public Static BooleanVidnumbycode (String idnum) {//coefficient list int[] Ratioarr = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; //Verification Code List Char[] checkcodelist = {' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 '}; //get the ID number character array Char[] CIds =Idnum.tochararray (); //get the last one (ID check code) CharOcode =Cids[id_length]; int[] IIDs =New int[Id_length]; intidsum = 0;//identification number 第1-17位 and the sum of the coefficients intresidue = 0;//remainder (by adding out and dividing by 11, see what the remainder is?) ) for(inti = 0; i < id_length; i++) {Iids[i]= cids[i]-' 0 '; Idsum+ = iids[i] *Ratioarr[i]; } Residue= idsum% 11;//get remainder returnCharacter.touppercase (ocode) = =Checkcodelist[residue]; } Public Static BooleanvId (String idnum) {returnVidnumbycode (Idnum) &&Vidnumbyregex (Idnum); } Public Static voidMain (string[] args) {String idnum= "430103197309300519"; System.out.println (VId (idnum)); }}
Java determines identity card validity