{"id":112,"date":"2021-10-03T16:10:53","date_gmt":"2021-10-03T08:10:53","guid":{"rendered":"https:\/\/www.miie.net\/?p=112"},"modified":"2021-10-03T16:10:53","modified_gmt":"2021-10-03T08:10:53","slug":"cs-idcard-validation","status":"publish","type":"post","link":"https:\/\/diji.net\/?p=112","title":{"rendered":"C#\u9a8c\u8bc1\u8eab\u4efd\u8bc1\u53f7\u7801\u6b63\u786e\u6027"},"content":{"rendered":"<p>18\u4f4d\u53f7\u7801\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nprivate static bool CheckIDCard18(string Id)\n        {\n            long n = 0;\n            if (long.TryParse(Id.Remove(17), out n) == false || n &lt; Math.Pow(10, 16) || long.TryParse(Id.Replace('x', '0').Replace('X', '0'), out n) == false)\n            {\n                return false;\n            }\n            string address = &quot;11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91&quot;;\n            if (address.IndexOf(Id.Remove(2)) == -1)\n            {\n                return false;\n            }\n            string birth = Id.Substring(6, 8).Insert(6, &quot;-&quot;).Insert(4, &quot;-&quot;);\n            DateTime time = new DateTime();\n            if (DateTime.TryParse(birth, out time) == false)\n            {\n                return false;\n            }\n            string&#x5B;] arrVarifyCode = (&quot;1,0,x,9,8,7,6,5,4,3,2&quot;).Split(',');\n            string&#x5B;] Wi = (&quot;7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2&quot;).Split(',');\n            char&#x5B;] Ai = Id.Remove(17).ToCharArray();\n            int sum = 0;\n            for (int i = 0; i &lt; 17; i++)\n            {\n                sum += int.Parse(Wi&#x5B;i]) * int.Parse(Ai&#x5B;i].ToString());\n            }\n            int y = -1;\n            Math.DivRem(sum, 11, out y);\n            if (arrVarifyCode&#x5B;y] != Id.Substring(17, 1).ToLower())\n            {\n                return false;\n            }\n            return true;\/\/\u6b63\u786e\n        }\n<\/pre>\n<\/p>\n<p>15\u4f4d\u53f7\u7801\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nprivate static bool CheckIDCard15(string Id)\n        {\n            long n = 0;\n            if (long.TryParse(Id, out n) == false || n &lt; Math.Pow(10, 14))\n            {\n                return false;\n            }\n            string address = &quot;11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91&quot;;\n            if (address.IndexOf(Id.Remove(2)) == -1)\n            {\n                return false;\n            }\n            string birth = Id.Substring(6, 6).Insert(4, &quot;-&quot;).Insert(2, &quot;-&quot;);\n            DateTime time = new DateTime();\n            if (DateTime.TryParse(birth, out time) == false)\n            {\n                return false;\n            }\n            return true;\/\/\u6b63\u786e\n        }\n<\/pre>\n<\/p>\n<p>\u539f\u6587\u8fde\u63a5\uff1a<a href=\"https:\/\/www.cnblogs.com\/lvlinlv\/p\/7228966.html\"><a href=\"https:\/\/www.cnblogs.com\/lvlinlv\/p\/7228966.html\">https:\/\/www.cnblogs.com\/lvlinlv\/p\/7228966.html<\/a><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>18\u4f4d\u53f7\u7801\uff1a private static bool CheckIDCard18(string Id) { long n = 0; if (long.TryParse(Id.Remove(17), out n) == false || n &lt; Math.Pow(10, 16) || long.TryParse(Id.Replace(&#8216;x&#8217;, &#8216;0&#8217;).Replace(&#8216;X&#8217;, &#8216;0&#8217;), out n) == false) { return false; } string address = &quot;11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91&quot;; if (address.IndexOf(Id.Remove(2)) == -1) { return false; } string birth = Id.Substring(6, 8).Insert(6, &quot;-&quot;).Insert(4, &quot;-&quot;); DateTime time [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-csharp"],"_links":{"self":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=112"}],"version-history":[{"count":0,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions"}],"wp:attachment":[{"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}