/// <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 bool CheckIDCard18 (string Id)
{
Long n = 0;
If (long. tryParse (Id. remove (17), out n) = false | n <Math. pow (10, 16) | long. tryParse (Id. replace ('x', '0 '). replace ('x', '0'), out n) = false)
{
Return false; // digit Verification
}
String address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91 ";
If (address. IndexOf (Id. Remove (2) =-1)
{
Return false; // province Verification
}
String birth = Id. Substring (6, 8). Insert (6, "-"). Insert (4 ,"-");
DateTime time = new DateTime ();
If (DateTime. TryParse (birth, out time) = false)
{
Return false; // birthday Verification
}
String [] arrVarifyCode = (", 0, x, 9, 8, 4,"). Split (',');
String [] Wi = (","). Split (',');
Char [] Ai = Id. Remove (17). ToCharArray ();
Int sum = 0;
For (int I = 0; I <17; I ++)
{
Sum + = int. Parse (Wi [I]) * int. Parse (Ai [I]. ToString ());
}
Int y =-1;
Math. DivRem (sum, 11, out y );
If (arrVarifyCode [y]! = Id. Substring (17, 1). ToLower ())
{
Return false; // Verification Code
}
Return true; // conforms to GB11643-1999 standards
}
/// <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 bool CheckIDCard15 (string Id)
{
Long n = 0;
If (long. TryParse (Id, out n) = false | n <Math. Pow (10, 14 ))
{
Return false; // digit Verification
} Www.2cto.com
String address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91 ";
If (address. IndexOf (Id. Remove (2) =-1)
{
Return false; // province Verification
}
String birth = Id. Substring (6, 6). Insert (4, "-"). Insert (2 ,"-");
DateTime time = new DateTime ();
If (DateTime. TryParse (birth, out time) = false)
{
Return false; // birthday Verification
}
Return true; // meets the 15-digit ID card Standard
}