gpt4 book ai didi

c# - 身份证号码验证

转载 作者:太空宇宙 更新时间:2023-11-03 20:16:29 25 4
gpt4 key购买 nike

我想为我的小应用程序验证国民身份证号码。

There are only 9 digits
there is a letter at the end 'x' or 'v' (both capital and simple letters)
3rd digit can not be equal to 4 or 9

如何使用 visual studio 2010 验证这一点?我可以使用正则表达式来验证吗?

最佳答案

你可以在没有 REGEX 的情况下这样做:

string str = "124456789X";
if ((str.Count(char.IsDigit) == 9) && // only 9 digits
(str.EndsWith("X", StringComparison.OrdinalIgnoreCase)
|| str.EndsWith("V", StringComparison.OrdinalIgnoreCase)) && //a letter at the end 'x' or 'v'
(str[2] != '4' && str[2] != '9')) //3rd digit can not be equal to 4 or 9
{
//Valid

}
else
{
//invalid
}

关于c# - 身份证号码验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16351929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com