C#--添加对象前 - 身份证号的验证

验证是否符合通用验证类的要求

调用通用验证类
这里写图片描述


通过数据验证
这里写图片描述

这里写图片描述


验证身份证号是否存在SQL

如果SQL有了身份证信息新增的身份证号不能是重复的
这里写图片描述

编写查询身份证方法
这里写图片描述

 /// <summary>
        /// 查询身份证是否已经存在
        /// </summary>
        /// <param name="idcard"></param>
        /// <returns></returns>
        public bool IsIdCardExisted(string idcard)
        {
            string sql = "Select count(*) from Students where StudentIdNo={0}";
            sql = string.Format(sql, idcard);
            int count = Convert.ToInt32(SQLHelper.GetSingleResult(sql));
            if (count == 1) return true;
            else return false;
        }

通过数据验证

这里写图片描述

SQL已经有了存在的身份证号,新增的身份证号重复不通过

这里写图片描述


验证身份证是否与出生日期吻合

这里写图片描述

这里写图片描述

  //验证身份证号是否和出生日期吻合
            string month = string.Empty;
            string day = string.Empty;
            if(Convert.ToDateTime(this.txtBirthday.Text).Month<10)        
                month = "0" + Convert.ToDateTime(this.txtBirthday.Text).Month.ToString();          
            else         
                month = Convert.ToDateTime(this.txtBirthday.Text).Month.ToString();
            if (Convert.ToDateTime(this.txtBirthday.Text).Day < 10)
                day = "0" + Convert.ToDateTime(this.txtBirthday.Text).Day.ToString();
            else
                day = Convert.ToDateTime(this.txtBirthday.Text).Day.ToString();
            string birthday = Convert.ToDateTime(this.txtBirthday.Text).Year.ToString() + month + day;

            if(!this.txtStuIdNo.Text.Trim().Contains(birthday))
            {
                MessageBox.Show("身份证号和出生日期不匹配", "验证提示");
                this.txtStuIdNo.Focus();
                this.txtStuIdNo.SelectAll();
                return;

            }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值