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