SoFunction
Updated on 2025-03-07

C# implements a method to verify whether the ID card is legal

This article describes the method of C# to verify whether an ID card is legal. Share it for your reference. The specific analysis is as follows:

This C# code mainly verifies whether the beginning of the ID card and the format and length of the ID card are correct, and does not strictly verify according to the encoding rules of the ID card

/// <summary>
/// Verify whether the ID card is legal/// </summary>
/// <param name="idCard">ID card to be verified</param>public static bool IsIdCard(string idCard)
{
  //If it is empty, the verification is considered qualified  if (IsNullOrEmpty(idCard))
  {
 return true;
  }
  //Clear the spaces in the string to be validated  idCard = ();
  //Mode string  StringBuilder pattern = new StringBuilder();
  (@"^(11|12|13|14|15|21|22|23|31|32|33|34|35|36|37|41|42|43|44|45|46|");
  (@"50|51|52|53|54|61|62|63|64|65|71|81|82|91)");
  (@"(\d{13}|\d{15}[\dx])$");
  //verify  return (idCard, ());
}

I hope this article will be helpful to everyone's C# programming.