ID card number verification and related!

Source: Internet
Author: User

2015-11-16 16:35:32

lowercase to uppercase: ToUpper ();

Uppercase to lowercase: toLower ();

Replacement: replace (' X ', ' Y ');

Converts a string to a character array: ToCharArray ();

Remove y characters from x: string.substring (ing x,int y);

Insert Y:string.insert (int x,string Y) at X;

Split with x: String. Split (' x ');

To verify the 18-bit ID number (including lowercase x):  

1        /// <summary>  2         ///18-digit ID number verification3         /// </summary>  4         Private BOOLCheckIDCard18 (stringidNumber)5         {  6             Longn =0; 7             if(Long. TryParse (Idnumber.remove ( -), outN) = =false   8|| N < Math.pow (Ten, -) ||Long. TryParse (Idnumber.replace ('x','0'). Replace ('X','0'), outN) = =false)  9             {  Ten                 return false;//Digital Verification One             }   A             stringAddress ="11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";  -             if(Address. IndexOf (Idnumber.remove (2)) == -1)   -             {   the                 return false;//Province Verification -             }   -             stringBirth = idnumber.substring (6,8). Insert (6,"-"). Insert (4,"-");  -DateTime time =NewDateTime ();  +             if(Datetime.tryparse (Birth, outtime) = =false)   -             {   +                 return false;//Birthday Verification A             }   at             string[] Arrvarifycode = ("1,0,x,9,8,7,6,5,4,3,2"). Split (',');  -             string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2"). Split (',');  -             Char[] Ai = Idnumber.remove ( -).  ToCharArray ();  -             intsum =0;  -              for(inti =0; I < -; i++)   -             {   inSum + =int. Parse (Wi[i]) *int. Parse (Ai[i].  ToString ());  -             }   to             inty =-1;  +Math.divrem (SUM, One, outy);  -             if(Arrvarifycode[y]! = idnumber.substring ( -,1). ToLower ()) the             {   *                 return false;//Check Code Verification $             }  Panax Notoginseng             return true;//complies with gb11643-1999 standards -}
View Code

Verify the 15-digit ID number:  

1         /// <summary>  2         ///15-digit ID number verification3         /// </summary>  4         Private BOOLCHECKIDCARD15 (stringidNumber)5         {  6             Longn =0; 7             if(Long. TryParse (IdNumber, outN) = =false|| N < Math.pow (Ten, -))  8             {  9                 return false;//Digital VerificationTen             }   One             stringAddress ="11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";  A             if(Address. IndexOf (Idnumber.remove (2)) == -1)   -             {   -                 return false;//Province Verification the             }   -             stringBirth = idnumber.substring (6,6). Insert (4,"-"). Insert (2,"-");  -DateTime time =NewDateTime ();  -             if(Datetime.tryparse (Birth, outtime) = =false)   +             {   -                 return false;//Birthday Verification +             }   A             return true;  at}
View Code

ID card number verification and related!

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.