//验证是不是合法的18位身份证号码代码:
public static bool IsValidIDNumber(string strId)
{
System.Text.RegularExpressions.Regex regId
= new
System.Text.RegularExpressions.Regex(@"^\d{17}(\d|x)$"
, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (strId.Length != 18)
{
return false;
}
else
{
if (!regId.IsMatch(strId))
{
return false;
}
else
{
int iS = 0;
int[] iW = new int[]
{
7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2
};
string LastCode = "10X98765432";
for (int i = 0; i < 17; i++)
{
iS += int.Parse(strId.Substring(i, 1)) * iW[i];
}
int iY = iS % 11;
if (strId.Substring(17, 1) != LastCode.Substring(iY, 1))
return false;
return true;
}
}
}
验证是不是合法的18位身份证号码代码
最新推荐文章于 2022-10-22 20:42:42 发布