Regular expressions Use the

Source: Internet
Author: User

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

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.