验证二代身份证真假

2 篇文章 0 订阅
2 篇文章 0 订阅

看了几天的视频,做了一个小程序,查询你的二代身份证是否是真的

源代码如下:

 

namespace 验证身份证算法
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnview_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.ToString()))
         {
                MessageBox.Show("号码不能为空");
                textBox1.Focus();
                return;
          
         }
            if (textBox1.TextLength !=18 )
            {
                MessageBox.Show("输入的号码长度为18位");
                return;

            }
            int sum = 0;
            string checkwei = "10x98765432";
            string ID = textBox1.Text;
            string number17 = ID.Substring(0, 17);
            string number18 = ID.Substring(17);
            int[] Wquan = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
            for (int i = 0; i < 17; i++)
            {
                sum = sum + Wquan[i] * Convert.ToInt32(number17[i].ToString());
            }
            string result = checkwei[sum % 11].ToString();
            if (result.Equals(number18,StringComparison.OrdinalIgnoreCase))
            {
                MessageBox.Show("身份证合法");
                this.pic朱逢娅.Visible = true;
            }
            else
            {
                MessageBox.Show("身份证不合法");
            }
            int 年龄 = Convert.ToInt32(textBox1.Text.Substring(6,4 ));
            int year = DateTime.Now.Year - 年龄;
            if (year <18)
            {
                this.pic朱逢娅.Visible = false;
                MessageBox.Show("年龄太小回家看动画片吧");
            }

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar < '0' || e.KeyChar > '9')
            {
                e.Handled = true;
            }
            if (e.KeyChar ==8)
            {
                e.Handled = false;
               
            }
      
            //440524188001010014
            //4405,2418,8001,0100,14
           
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            pic朱逢娅.Visible = false;
       
        }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值