using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 身份证验证
{
public partial class 隐藏文件查看 : Form
{
public 隐藏文件查看()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text;
char[] chars = str1.ToCharArray();
for (int i = 0; i < str1.Length; i++)
{
//int i3;
//if (!i3==Convert.ToInt32(chars[i]))
//{
// MessageBox.Show("身份证不能含有字母");
// return;
//} 一个个扫描我输入的全是数字,这段代码要怎么写的
if (str1.Length != 18)//身份证为的位数要为18位
{
MessageBox.Show("请输入正确的身份证!");
return;
}
string str2 = str1.Substring(6, 4);
int i1;
if (!int.TryParse(str2, out i1))//截取的四位不是数字
{
MessageBox.Show("你的身份证不能正常识别");
return;
}
int i2 = DateTime.Now.Year;
if (i2 - i1 >= 18)//年龄要大于18岁
{
pictureBox1.Visible = true;
}
else
{
pictureBox1.Visible = false;
MessageBox.Show("对不起,还没有到十八岁!");
return;
}
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 身份证验证
{
public partial class 隐藏文件查看 : Form
{
public 隐藏文件查看()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text;
char[] chars = str1.ToCharArray();
for (int i = 0; i < str1.Length; i++)
{
//int i3;
//if (!i3==Convert.ToInt32(chars[i]))
//{
// MessageBox.Show("身份证不能含有字母");
// return;
//} 一个个扫描我输入的全是数字,这段代码要怎么写的
if (str1.Length != 18)//身份证为的位数要为18位
{
MessageBox.Show("请输入正确的身份证!");
return;
}
string str2 = str1.Substring(6, 4);
int i1;
if (!int.TryParse(str2, out i1))//截取的四位不是数字
{
MessageBox.Show("你的身份证不能正常识别");
return;
}
int i2 = DateTime.Now.Year;
if (i2 - i1 >= 18)//年龄要大于18岁
{
pictureBox1.Visible = true;
}
else
{
pictureBox1.Visible = false;
MessageBox.Show("对不起,还没有到十八岁!");
return;
}
}
}
}
}
{
不能输入字母
}
{
messagebox.show(不能为字母);
}
if(Regex.IsMatch(身份证,@"^(^\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$"))
{
MessageBox.Show("请输入正确的身份证号码);
return;
}
各个地区身份证号码也是有区别的、
自己百度下身份证号码正则表达式
Regex.IsMatch(输入,"[0-9]+")
身份证的验证就需要的动态的生成了。
因为你不同的地区,不同的年龄,不同的姓别,都会生成匹配的正则表达的结果,通用的你可以百度一下。