• C# 根据身份证号码判断出生日期和性别


                    //获取得到输入的身份证号码
                    string identityCard = textBox_IdentityCard.Text.Trim();
    
                    if (string.IsNullOrEmpty(identityCard))
                    {
                        //身份证号码不能为空,如果为空返回
                        MessageBox.Show("身份证号码不能为空!");
                        if (textBox_IdentityCard.CanFocus)
                        {
                            textBox_IdentityCard.Focus();//设置当前输入焦点为textBox_IdentityCard
                        }
                        return;
                    }
                    else
                    {
                        //身份证号码只能为15位或18位其它不合法
                        if (identityCard.Length != 15 && identityCard.Length != 18)
                        {
                            MessageBox.Show("身份证号码为15位或18位,请检查!");
                            if (textBox_IdentityCard.CanFocus)
                            {
                                textBox_IdentityCard.Focus();
                            }
                            return;
                        }
                    }
    
                    string birthday = "";
                    string sex = "";
    
                    //处理18位的身份证号码从号码中得到生日和性别代码
                    if (identityCard.Length == 18)
                    {
                        birthday = identityCard.Substring(6, 4) + "-" + identityCard.Substring(10, 2) + "-" + identityCard.Substring(12, 2);
                        sex = identityCard.Substring(14, 3);
                    }
                    //处理15位的身份证号码从号码中得到生日和性别代码
                    if (identityCard.Length == 15)
                    {
                        birthday = "19" + identityCard.Substring(6, 2) + "-" + identityCard.Substring(8, 2) + "-" + identityCard.Substring(10, 2);
                        sex = identityCard.Substring(12, 3);
                    }
                    textBox_Birthday.Text = birthday;
                    //性别代码为偶数是女性奇数为男性
                    if (int.Parse(sex) % 2 == 0)
                    {
                        this.comboBox_Sex.Text = "";
                    }
                    else
                    {
                        this.comboBox_Sex.Text = "";
                    }
  • 相关阅读:
    Mysql group_concat
    canvas toDataUrl 跨域问题
    Svg操作
    java 判断浏览器
    排序操作
    java 格式判断
    你真的了解 console 吗
    svg转换工具
    java图片缩放
    常见 银行贷款 名词
  • 原文地址:https://www.cnblogs.com/qingjiawen/p/16139339.html
Copyright © 2020-2023  润新知