一般身份证验证
来源:互联网 发布:八爪鱼采集器 知乎 编辑:程序博客网 时间:2024/06/11 20:48
using System.Text;
/**//// <summary>
/// personcard 的摘要说明
/// </summary>
public class personcard
...{
public personcard()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public iddataclass checkcidinfo(string cid)
...{
iddataclass _ciddata = new iddataclass();
if (!LiTianPing.DBUtility.DbHelperSQL.Exists("select count(*) from per_user where p_card='" + cid + "'"))
...{
string[] acity = new string[] ...{ null, null, null, null, null, null, null, null, null, null, null, "北京", "天津", "河北", "山西", "内蒙古", null, null, null, null, null, "辽宁", "吉林", "黑龙江", null, null, null, null, null, null, null, "上海", "江苏", "浙江", "安微", "福建", "江西", "山东", null, null, null, "河南", "湖北", "湖南", "广东", "广西", "海南", null, null, null, "重庆", "四川", "贵州", "云南", "西藏", null, null, null, null, null, null, "陕西", "甘肃", "青海", "宁夏", "新疆", null, null, null, null, null, "台湾", null, null, null, null, null, null, null, null, null, "香港", "澳门", null, null, null, null, null, null, null, null, "国外" };
double isum = 0;
System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^d{17}(d|x)$|^d{15}$");
System.Text.RegularExpressions.Match mc = rg.Match(cid);
if (!mc.Success)
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "不是有效的身份证号";
return _ciddata;
}
if (cid.Length == 15) cid = this.convert15to18(cid);
cid = cid.ToLower();
cid = cid.Replace("x", "a");
if (acity[int.Parse(cid.Substring(0, 2))] == null)
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "非法地区";
return _ciddata;
}
try
...{
DateTime.Parse(cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2));
}
catch
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "非法生日";
return _ciddata;
}
for (int i = 17; i >= 0; i--)
...{
isum += (System.Math.Pow(2, i) % 11) * int.Parse(cid[17 - i].ToString(), System.Globalization.NumberStyles.HexNumber);
}
if (isum % 11 != 1)
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "非法证号";
return _ciddata;
}
if (Convert.ToInt32(cid.Substring(6, 4)) < 1989)
...{
_ciddata.isvalid = true;
_ciddata.chkinfo = acity[int.Parse(cid.Substring(0, 2))] + "," + cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2) + "," + (int.Parse(cid.Substring(16, 1)) % 2 == 1 ? "男" : "女");
return _ciddata;
}
else
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "年龄太小";
return _ciddata;
}
}
else
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "此身份证已经注册";
return _ciddata;
}
}
//将15位身份证号码转换为18位
private string convert15to18(string cid)
...{
char[] strjiaoyan = ...{ '1','0', 'x', '9', '8', '7', '6', '5', '4', '3', '2' };
int[] intquan = ...{ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };
string strtemp;
int inttemp = 0;
strtemp = cid.Substring(0, 6) + "19" + cid.Substring(6);
for (int i = 0; i <= strtemp.Length - 1; i++)
...{
inttemp += int.Parse(strtemp.Substring(i, 1)) * intquan[i];
}
inttemp = inttemp % 11;
return strtemp + strjiaoyan[inttemp];
}
}
//用于保存身份证验证结果的类
public class iddataclass
...{
public iddataclass()
...{
}
public bool isvalid;
public string chkinfo;
}
/**//// <summary>
/// personcard 的摘要说明
/// </summary>
public class personcard
...{
public personcard()
...{
//
// TODO: 在此处添加构造函数逻辑
//
}
public iddataclass checkcidinfo(string cid)
...{
iddataclass _ciddata = new iddataclass();
if (!LiTianPing.DBUtility.DbHelperSQL.Exists("select count(*) from per_user where p_card='" + cid + "'"))
...{
string[] acity = new string[] ...{ null, null, null, null, null, null, null, null, null, null, null, "北京", "天津", "河北", "山西", "内蒙古", null, null, null, null, null, "辽宁", "吉林", "黑龙江", null, null, null, null, null, null, null, "上海", "江苏", "浙江", "安微", "福建", "江西", "山东", null, null, null, "河南", "湖北", "湖南", "广东", "广西", "海南", null, null, null, "重庆", "四川", "贵州", "云南", "西藏", null, null, null, null, null, null, "陕西", "甘肃", "青海", "宁夏", "新疆", null, null, null, null, null, "台湾", null, null, null, null, null, null, null, null, null, "香港", "澳门", null, null, null, null, null, null, null, null, "国外" };
double isum = 0;
System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^d{17}(d|x)$|^d{15}$");
System.Text.RegularExpressions.Match mc = rg.Match(cid);
if (!mc.Success)
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "不是有效的身份证号";
return _ciddata;
}
if (cid.Length == 15) cid = this.convert15to18(cid);
cid = cid.ToLower();
cid = cid.Replace("x", "a");
if (acity[int.Parse(cid.Substring(0, 2))] == null)
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "非法地区";
return _ciddata;
}
try
...{
DateTime.Parse(cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2));
}
catch
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "非法生日";
return _ciddata;
}
for (int i = 17; i >= 0; i--)
...{
isum += (System.Math.Pow(2, i) % 11) * int.Parse(cid[17 - i].ToString(), System.Globalization.NumberStyles.HexNumber);
}
if (isum % 11 != 1)
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "非法证号";
return _ciddata;
}
if (Convert.ToInt32(cid.Substring(6, 4)) < 1989)
...{
_ciddata.isvalid = true;
_ciddata.chkinfo = acity[int.Parse(cid.Substring(0, 2))] + "," + cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2) + "," + (int.Parse(cid.Substring(16, 1)) % 2 == 1 ? "男" : "女");
return _ciddata;
}
else
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "年龄太小";
return _ciddata;
}
}
else
...{
_ciddata.isvalid = false;
_ciddata.chkinfo = "此身份证已经注册";
return _ciddata;
}
}
//将15位身份证号码转换为18位
private string convert15to18(string cid)
...{
char[] strjiaoyan = ...{ '1','0', 'x', '9', '8', '7', '6', '5', '4', '3', '2' };
int[] intquan = ...{ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };
string strtemp;
int inttemp = 0;
strtemp = cid.Substring(0, 6) + "19" + cid.Substring(6);
for (int i = 0; i <= strtemp.Length - 1; i++)
...{
inttemp += int.Parse(strtemp.Substring(i, 1)) * intquan[i];
}
inttemp = inttemp % 11;
return strtemp + strjiaoyan[inttemp];
}
}
//用于保存身份证验证结果的类
public class iddataclass
...{
public iddataclass()
...{
}
public bool isvalid;
public string chkinfo;
}
- 一般身份证验证
- angularjs 验证身份证格式 和 一般JS验证身份证格式
- 身份证验证
- 身份证验证
- 身份证验证
- 身份证验证
- 身份证验证
- 验证身份证
- 身份证验证
- 身份证验证
- 身份证验证
- 身份证验证
- 身份证验证
- 身份证验证
- 身份证验证
- 身份证验证
- 验证身份证
- 身份证验证
- 关于未命名空间
- fedora8下载地址,用flashget下载超快
- UML
- 得到本机所有 IP 地址
- 测试图片
- 一般身份证验证
- 自定义控件中ViewSate在母版页中丢失的处理
- 堆和栈的区别
- 注册 用户名字的验证````
- 致面向对象技术初学者的一封公开信
- .NET Ajax错误汇总
- Steve Jobs-An innovative man
- 点击即变长的文本输入框
- HTML及JavaScript疑难31问,初学者必备