zoukankan      html  css  js  c++  java
  • C# 根据身份证号码获取简易信息

    public class PackIden
        {
            /// <summary>
            /// 根据身份证获取生日
            /// </summary>
            /// <param name="cardid">身份证</param>
            /// <param name="res">是否有格式(true1990-01-01,false19900101)</param>
            /// <returns></returns>
            public static string GetBirthdayByIdentityCardId(string cardid, bool res)
            {
                string birthday = string.Empty;
                System.Text.RegularExpressions.Regex regex = null;
    
                if (cardid.Length == 18)
                {
                    regex = new Regex(@"^d{17}(d|x)$");
                    if (regex.IsMatch(cardid))
                    {
                        if (res)
                            birthday = cardid.Substring(6, 8).Insert(4, "-").Insert(7, "-");
                        else
                            birthday = cardid.Substring(6, 8);
                    }
                    else
                    {
                        birthday = "invalid cardid";
                    }
                }
                else if (cardid.Length == 15)
                {
                    regex = new Regex(@"^d{15}");
                    if (regex.IsMatch(cardid))
                    {
                        if (res)
                            birthday = cardid.Substring(6, 6).Insert(2, "-").Insert(5, "-");
                        else
                            birthday = cardid.Substring(6, 6);
                    }
                    else
                    {
                        birthday = "invalid cardid";
                    }
                }
                else
                {
                    birthday = "invalid cardid";
                }
    
                return birthday;
            }
    
    
            /// <summary>
            /// 根据身份证获取身份证信息
            /// 18位身份证
            /// 0地区代码(1~6位,其中1、2位数为各省级政府的代码,3、4位数为地、市级政府的代码,5、6位数为县、区级政府代码)
            /// 1出生年月日(7~14位)
            /// 2顺序号(15~17位单数为男性分配码,双数为女性分配码)
            /// 3性别
            /// 
            /// 15位身份证
            /// 0地区代码 
            /// 1出生年份(7~8位年,9~10位为出生月份,11~12位为出生日期 
            /// 2顺序号(13~15位),并能够判断性别,奇数为男,偶数为女
            /// 3性别
            /// </summary>
            /// <param name="cardId"></param>
            /// <returns></returns>
            public static string[] GetCardIdInfo(string cardId)
            {
                string[] info = new string[4];
                System.Text.RegularExpressions.Regex regex = null;
                if (cardId.Length == 18)
                {
                    regex = new Regex(@"^d{17}(d|x)$");
                    if (regex.IsMatch(cardId))
                    {
                        info.SetValue(cardId.Substring(0, 6), 0);
                        info.SetValue(cardId.Substring(6, 8), 1);
                        info.SetValue(cardId.Substring(14, 3), 2);
                        info.SetValue(Convert.ToInt32(info[2]) % 2 != 0 ? "" : "", 3);
                    }
                }
                else if (cardId.Length == 15)
                {
                    regex = new Regex(@"^d{15}");
                    if (regex.IsMatch(cardId))
                    {
                        info.SetValue(cardId.Substring(0, 6), 0);
                        info.SetValue(cardId.Substring(6, 6), 1);
                        info.SetValue(cardId.Substring(12, 3), 2);
                        info.SetValue(Convert.ToInt32(info[2]) % 2 != 0 ? "" : "", 3);
                    }
                }
    
                return info;
    
            }
    
        }
  • 相关阅读:
    1380. Lucky Numbers in a Matrix
    672. Bulb Switcher II
    1375. Bulb Switcher III
    1376. Time Needed to Inform All Employees
    1372. Longest ZigZag Path in a Binary Tree
    PHP中curl_multi并发详解【转】
    php中$_REQUEST、$_POST、$_GET的区别【转】
    Post请求的两种编码格式:application/x-www-form-urlencoded和multipart/form-data【转】
    PHP $_FILES函数详解【转】
    php接收二进制流【转】
  • 原文地址:https://www.cnblogs.com/fjptwwf/p/5687255.html
Copyright © 2011-2022 走看看