看了几天的视频,做了一个小程序,查询你的二代身份证是否是真的
源代码如下:
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();
}
程序下载地址
http://nj.disk.ftn.qq.com/ftn_handler/69a7c1f3e3a17e4421801f15dd174569cd01afd1ec84583ef561ab0a2046023fe38e095de54df0391178596a8c514bc06e1195dfe1ff319401e7dae46a2ef451/验证身份证算法.rar?k=233238329373ce991591bd501264074953570d50555c000349060807554906035d071550065d0a4b07000c03515d025152055d03347632b78de49cfbd9d3efb0c0f9db859c4a4007163205&fr=01&&txf_fid=92168ff9e3a4291d06e26b872c4d40b4b3ab7a40
|