. Net ID card number verification

Source: Internet
Author: User

UsingSystem;

/// <Summary>
/// Summary description for IDCardValid
/// </Summary>
Public ClassIDCardValid
{
PublicIDCardValid ()
{
//
// TODO: Add constructor logic here
//
}

/// <Summary>
/// Verify the ID card number
/// </Summary>
/// <Param name = "Id"> Id card number </param>
/// <Returns> If the verification succeeds, the value is True; otherwise, the value is False. </returns>
Public Static BoolCheckIDCard (StringId)
{
If(Id. Length = 18)
{
BoolCheck = CheckIDCard18 (Id );
ReturnCheck;
}
Else If(Id. Length = 15)
{
BoolCheck = CheckIDCard15 (Id );
ReturnCheck;
}
Else
{
Return False;
}
}
# Region ID card number verification

/// <Summary>
/// Verify the 15-digit ID card number
/// </Summary>
/// <Param name = "Id"> Id card number </param>
/// <Returns> If the verification succeeds, the value is True; otherwise, the value is False. </returns>
Private Static BoolCheckIDCard18 (StringId)
{
LongN = 0;
If(Long. TryParse (Id. Remove (17 ),OutN) =False| N <Math. Pow (10, 16) |Long. TryParse (Id. Replace ('X','0'). Replace ('X','0'),OutN) =False)
{
Return False;// Digit Verification
}
StringAddress ="11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62 x 15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
If(Address. IndexOf (Id. Remove (2) =-1)
{
Return False;// Province Verification
}
StringBirth = Id. Substring (6, 8). Insert (6,"-"). Insert (4,"-");
DateTime time =NewDateTime ();
If(DateTime. TryParse (birth,OutTime) =False)
{
Return False;// Birthday Verification
}
String[] ArrVarifyCode = (", X, 9, 8, 5, 4, 3, 2"). Split (',');
String[] Wi = (", 2"). Split (',');
Char[] Ai = Id. Remove (17). ToCharArray ();
IntSum = 0;
For(IntI = 0; I <17; I ++)
{
Sum + =Int. Parse (Wi [I]) *Int. Parse (Ai [I]. ToString ());
}
IntY =-1;
Math. DivRem (sum, 11,OutY );
If(ArrVarifyCode [y]! = Id. Substring (17, 1). ToLower ())
{
Return False;// Verification Code
}
Return True;// Complies with GB11643-1999 standards
}

/// <Summary>
/// Verify the 18-digit ID card number
/// </Summary>
/// <Param name = "Id"> Id card number </param>
/// <Returns> If the verification succeeds, the value is True; otherwise, the value is False. </returns>
Private Static BoolCheckIDCard15 (StringId)
{
LongN = 0;
If(Long. TryParse (Id,OutN) =False| N <Math. Pow (10, 14 ))
{
Return False;// Digit Verification
}
StringAddress ="11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62 x 15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
If(Address. IndexOf (Id. Remove (2) =-1)
{
Return False;// Province Verification
}
StringBirth = Id. Substring (6, 6). Insert (4,"-"). Insert (2,"-");
DateTime time =NewDateTime ();
If(DateTime. TryParse (birth,OutTime) =False)
{
Return False;// Birthday Verification
}
Return True;// Meets the 15-digit ID card Standard
}
# Endregion
}

China ID card number verification

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.