一个简单的身份证校验

/// <summary>
    /// 18位身份证验证。比较简单的验证。但基本够用了
    /// </summary>
    private void TestValidateIdCard()
        {
            Regex regex = new Regex(@"^[1-9]d{5}[1-9]d{3}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}([0-9]|X|x)$" );
           
            IList<string > ids=new List<string >()
            {
                "422130198701010101",
                "022130198701010101",
                "422130098701010001",
                "42213018701010101",
                "422130198704330101",
                "42213019870101010Y",
                "42213019870101010X",
                "42213019870101010x"
            };


            foreach (string id in ids)
            {
                bool b = regex.IsMatch(id);
                Console.WriteLine(" {0} : {1} ",id,b);
            }
        }
原文地址:https://www.cnblogs.com/leiwei/p/3439596.html