美文网首页
C# 正则提取18位身份证号码

C# 正则提取18位身份证号码

作者: Rinaloving | 来源:发表于2023-03-30 13:18 被阅读0次

正则提取18位身份证号码

public static string GetRealIdCardNumber(string input)
        {
            var result = string.Empty;
            if (!string.IsNullOrWhiteSpace(input))
            {
                input = input.Replace(" ", "");
                List<string> list = new List<string>();
                Regex regex = new Regex(@"([1-9]\d{5}[12]\d{3}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])\d{3}[0-9xX])");
                MatchCollection collection = regex.Matches(input);

                if (collection.Count > 0 && collection[0].Groups.Count > 0)
                {
                    result = collection[0].Groups[0].Value;
                }
            }
            return result;
        }

相关文章

网友评论

      本文标题:C# 正则提取18位身份证号码

      本文链接:https://www.haomeiwen.com/subject/wztcddtx.html