人事专员MM跟我说做人事系统要根据输入的身份证号码得到出生日期和性别以减轻前台MM录入员工资料时的工作量,原来身份证号码里面的信息大有乾坤,以18位的身份证来说,前面六位代表了你户籍所在地,第七位到第十四位代表了你的出生年月,第十五位到第十七为代表了你的性别(偶数为女,奇数为男),根据这一信息,我在系统开发的录入员工的身份证后控件焦点转移时根据身份证号码获得生日和性别,用C#写的代码如下:

 

 /// <summary>
        /// 在控件验证 textBox_IdentityCard 的 Validated事件中定义身份证号码的合法性并根据身份证号码得到生日和性别
        /// </summary>
        private void textBox_IdentityCard_Validated(object sender, EventArgs e)
        {
            try
            {
                string identityCard = textBox_IdentityCard.Text.Trim();//获取得到输入的身份证号码

                if (string.IsNullOrEmpty(identityCard))
                {
                    MessageBox.Show("身份证号码不能为空!");//身份证号码不能为空,如果为空返回
                    if (textBox_IdentityCard.CanFocus)
                    {
                        textBox_IdentityCard.Focus();//设置当前输入焦点为textBox_IdentityCard
                    }
                    return;
                }
                else
                {
                    if (identityCard.Length != 15 && identityCard.Length != 18)//身份证号码只能为15位或18位其它不合法
                    {
                

相关文章:

  • 2021-09-27
  • 2021-11-17
  • 2021-09-29
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
猜你喜欢
  • 2022-01-18
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案