Java determines identity card validity

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.