VS2022身份证号码信息验证器

 (- -)功能说明:

要求:根据以下规则对身份证号码进行验证,运行效果如图3-7所示。

(1)号码长度18 位。

(2) 18位全是数字。

(3)第7~ 10位是出生的年。

(4)倒数第2位号码,奇数为男性,偶数为女性。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IdCheck
{
    public partial class Id : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string s = TextBox1.Text;
            if (s.Length != 18)
                Label2.Text = "输入了非18位的数字";
            else
            {
                int k = 0;
                System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
                byte[] bytest = ascii.GetBytes(s);//字节是二进制数组的单位,不会浪费空间
                foreach (var it in bytest)
                {
                    if (it < 48 || it > 57)
                    {
                        Label2.Text = "输入了非法字符";
                        k = 1;
                    }
                       
                }
                if (k == 0)
                {
                    string year, month, day;
                    year = s.Substring(6, 4);
                    month= s.Substring(10, 2);   
                    day= s.Substring(12, 2);
                    Label2.Text="您出生于 "+year+"年"+month+"月"+day+"日";
                    if (bytest[16]%2==1)
                    {
                        Label2.Text += ",您的性别是 " + "男";
                    }
                    else
                        Label2.Text += ",您的性别是 " + "女";
                }
            }
        }
    }
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值