如何验证身份证所属地区(要求精确到区),谢谢! 如何验证身份证所属地区(要求精确到区),谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面那个地址是国家统计局的网站你可以去看看http://www.stats.gov.cn/tjbz/xzqhdm/t20070411_402397928.htm身份证的前6位是代表你是什么地方的,他是精确到县一级的..自己整理一下就可以查询了 private string CheckCidInfo(string 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; string info = ""; System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^\d{17}(\d|x)$"); System.Text.RegularExpressions.Match mc = rg.Match(cid); if (!mc.Success) { return "你输入的号码有误!"; } cid = cid.ToLower(); cid = cid.Replace("x", "a"); if (aCity[int.Parse(cid.Substring(0, 2))] == null) { return "非法地区"; } try { DateTime.Parse(cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2)); } catch { return "非法生日"; } for (int i = 17; i >= 0; i--) { iSum += (System.Math.Pow(2, i) % 11) * int.Parse(cid[17 - i].ToString(), System.Globalization.NumberStyles.HexNumber); } double intI = iSum % 11; // Response.Write(intI.ToString()); if (iSum % 11 != 1) { return ("非法证号"); } //return(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)); string strSex=""; if (int.Parse(cid.Substring(16, 1)) % 2 == 1) { strSex = "男"; } else { strSex = "女"; } return (aCity[int.Parse(cid.Substring(0, 2))] + "," + cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2) + "," + strSex); } protected void Button1_Click(object sender, EventArgs e) { Response.Write(CheckCidInfo(this.TextBox1.Text.ToString())); }通过这就可以查询了。 关于gridview分页的问题求助一下大家啊 关于文本框控制 大家讨论一下是尽量用代码好还是用控件好 CSDN的投票结果图是怎么做的? 数据集更新的问题 DataGrid中,如果何把某列的小数,用 % 分数显示,并且四舍五入,只保留两位小数 为什么不能新建项目 Help!!!为何文本框中的内容我在程序中得不到!!! 100分征求学习asp.net 的意见和建议? 怎么建不了ASP.NET WEB 的应用程序?救救我! 我该用哪个数据库连接控件? 字符串拆分问题
http://www.stats.gov.cn/tjbz/xzqhdm/t20070411_402397928.htm身份证的前6位是代表你是什么地方的,他是精确到县一级的..自己整理一下就可以查询了
{
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;
string info = "";
System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^\d{17}(\d|x)$");
System.Text.RegularExpressions.Match mc = rg.Match(cid);
if (!mc.Success)
{
return "你输入的号码有误!";
}
cid = cid.ToLower();
cid = cid.Replace("x", "a");
if (aCity[int.Parse(cid.Substring(0, 2))] == null)
{
return "非法地区";
}
try
{
DateTime.Parse(cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2));
}
catch
{
return "非法生日";
}
for (int i = 17; i >= 0; i--)
{
iSum += (System.Math.Pow(2, i) % 11) * int.Parse(cid[17 - i].ToString(), System.Globalization.NumberStyles.HexNumber); }
double intI = iSum % 11;
// Response.Write(intI.ToString());
if (iSum % 11 != 1)
{
return ("非法证号");
}
//return(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));
string strSex="";
if (int.Parse(cid.Substring(16, 1)) % 2 == 1)
{
strSex = "男";
}
else
{
strSex = "女";
}
return (aCity[int.Parse(cid.Substring(0, 2))] + "," + cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2) + "," + strSex);
} protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(CheckCidInfo(this.TextBox1.Text.ToString()));
}
通过这就可以查询了。