Determine if the ID number is of that type (1 is 15 bits, 2 is 18 bits, 3 is the organization code certificate, 0 is invalid) private int Panduancard (string str) {string ps15 = "^\\d{15}$"; String ps18 = "^\\d{17}" (\\d| X) $ ";//Organization Code certificate Regular String ZZJG =" ^[a-za-z0-9]{8}-[a-za-z0-9]$ "; Patterncompiler orocom = new Perl5compiler (); try {Pattern pattern1 = Orocom.compile (PS15); Pattern pattern2 = Orocom.compile (PS18); Pattern Zzpattern = Orocom.compile (ZZJG); Patternmatcher matcher = new Perl5matcher (), if (Matcher.contains (str, pattern1)) {return 1;} else if (matcher.contains (str, pattern2)) {return 2;} else if (matcher.contains (str, zzpattern)) {return 3;}} catch (Malformedpatternexception e) {e.printstacktrace ();} return 0;}
Determines whether 18-bit is an identity card private boolean isidcard (String str) {integer[] rows=new integer[17];for (int i = 0; i < rows.length; I + +) {Rows[i]=integer.parseint (Str.charat (i) + "");} Weights integer[] quanvalue={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};//check code string[] check={"1", "0", "X", "9", "8", "7", "6", " 5 "," 4 "," 3 "," 2 "};int tot=0;for (int i = 0; i < quanvalue.length; i++) {tot+=rows[i]*quanvalue[i];} int Yushu = Tot%11;return check[yushu].equals (str.substring). toUpperCase ());}
15-bit liters to 18-bit private string Shengwei (String str) {string newstring=str.substring (0, 6) + "+str.substring" (6, Str.length ()); integer[] rows=new integer[17];for (int i = 0; i < rows.length; i++) {Rows[i]=integer.parseint (Newstring.charat (i) +"");} Weights integer[] quanvalue={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};//check code string[] check={"1", "0", "X", "9", "8", "7", "6", " 5 "," 4 "," 3 "," 2 "};int tot=0;for (int i = 0; i < quanvalue.length; i++) {tot+=rows[i]*quanvalue[i];} int Yushu = Tot%11;return Newstring+check[yushu];}
Regular expressions Use the