Tested and available
public class Validateidentitycard {/** * function: Valid verification of ID card <br> * <br> * * ID card number Verification 1, the structure of the number of citizenship number is a feature combination code, by 10 Seven-bit digital ontology code and a checksum code composition. Order from left to right is: six-digit address code, * Eight-digit Birth date code, three-digit sequence code and a digital parity code. 2, Address code (the first six digits) * Indicates the coding object of the county (city, Flag, district) of the administrative area code, according to the provisions of the gb/t2260 implementation. 3, Birth date code (seventh to 14 digits) * Indicates the year, month, day of the encoding object's birth, executes according to GB/T7408 's stipulation, the year, the month, the day code does not use the separator character. 4, Sequence code (15th to 17 digits) * means that the same address code in the area identified by the same, the same year, the same month, the same day, the number of people born in order, the odd distribution of the order code to men, even allocated to women. 5, check code (18th digits) * (1) 17-digit body code weighted sum formula S = SUM (Ai * Wi), i = 0, ..., 16, first to the first 17 digits of the right to sum * Ai: The ID number that represents the position of the number Wi: The weighted factor on position I Wi:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 * 2 (2) compute modulo Y = mod (S, 11) (3) get the corresponding checksum code by modulo y:0 1 2 3 4 5 6 7 8 9 10 Check code: 1 0 * X
9 8 7 6 5 4 3 2 * * @param idstr * @return valid: Return true invalid: false * @throws parseexception/ public static Boolean Iscardid (String idstr) throws ParseException {string[] Valcodearr = {"1", "0", "X", "9", "8", "
7 "," 6 "," 5 "," 4 "," 3 "," 2 "}; String[] Wi = {"7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2"};
String Ai = ""; Length of ================ number 15-bit or 18-bit ================ if (idstr.length ()!= && idstr.length ()!=) {return
False }//======================= (end) ========================//================ number except the last one is digital ================ if (IDS
Tr.length () = = (Ai = idstr.substring (0, 17);
else if (idstr.length () = = = Ai = idstr.substring (0, 6) + "n" + idstr.substring (6, 15);
} if (Stringutils.isnotblanknumeric (Ai) = False) {return false; }//======================= (end) ========================//================ Birth date is valid ================ String StrY Ear = ai.substring (6, 10);//year string strmonth = Ai.substring (10, 12);//month string strday = ai.substring (12, 14);/month
Dateutils.isdate (Stryear.concat ("-"). Concat (Strmonth). Concat ("-"). Concat (strday)) = = False) {return false;
} GregorianCalendar gc = new GregorianCalendar (); SimpleDateFormat s = new SimpleDateFormat ("Yyyy-mm-dd");
if ((Gc.get (calendar.year)-Integer.parseint (stryear)) > 150 | |
(Gc.gettime (). GetTime ()-S.parse (Stryear + "-" + Strmonth + "-" + strday). GetTime ()) < 0) {return false; } if (Integer.parseint (strmonth) > 12 | |
Integer.parseint (strmonth) = = 0) {return false; } if (Integer.parseint (strday) > 31 | |
Integer.parseint (strday) = = 0) {return false;
int totalmulaiwi = 0; for (int i = 0; i < i++) {Totalmulaiwi = Totalmulaiwi + integer.parseint (string.valueof (Ai.charat (i))) * Intege
R.parseint (Wi[i]);
int modvalue = totalmulaiwi% 11;
String strverifycode = Valcodearr[modvalue];
Ai = ai + strverifycode;
if (idstr.length () = = (Ai.equals) {if (idstr) = = False) {return false;
} else {return true;
return true;
}/** * @param args * @throws parseexception/public static void main (string[] args) throws ParseException {
String idcardnum= "210102820826411"; String idcardnum= "210102198208264114 ";
String idcardnum = "411328199310201312";
Idcard id = new Idcard ();
System.out.println (Iscardid (idcardnum));
System.out.println (Cc.isdate ("1996-02-29")); }
}