javascript 判断18位身份证的正确与错误

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/huangwei999111/article/details/49814755
function   IDCard(Num)   
   {   
   if   (Num.length!=18)   
   return   false;   
   var   x=0;   
   var   y='';   
    
   for(i=18;i>=2;i--)   
   x   =   x   +   (square(2,(i-1))%11)*parseInt(Num.charAt(19-i-1));   
   x%=11;   
   y=12-x;   
   if   (x==0)   y='1';   
   if   (x==1)   y='0';   
   if   (x==2)   y='X';   
   return   y;   
   }   
   //   求得x的y次方   
   function   square(x,y)   
   {   
   var   i=1;   
   for   (j=1;j<=y;j++)   
   i*=x;   
   return   i;   
   }   
展开阅读全文

[经典]18位身份证源代码

06-14

声明:本代码来转自www.cnntec.com论坛..感谢www.cnntec.com论坛带给我这么好用的代码(当时我就用上了.验证感觉蛮爽的.就收藏了)rn rnprivate string CheckCidInfo(string cid)rn rn 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,"国外";rn double iSum=0;rn string info="";rn System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^\d17(\d|x)$");rn System.Text.RegularExpressions.Match mc = rg.Match(cid);rn if(!mc.Success)rn rn return "";rn rn cid = cid.ToLower();rn cid = cid.Replace("x","a");rn if(aCity[int.Parse(cid.Substring(0,2))]==null)rn rn return "非法地区";rn rn tryrn rn DateTime.Parse(cid.Substring(6,4)+"-"+cid.Substring(10,2)+"-"+cid.Substring(12,2));rn rn catchrn rn return "非法生日";rn rn for(int i=17;i>=0;i--)rn rn iSum +=(System.Math.Pow(2,i)%11)*int.Parse(cid[17-i].ToString(),System.Globalization.NumberStyles.HexNumber);rnrn rn if(iSum%11!=1)rn return("非法证号");rn rn 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?"男":"女"));rn rn rnrn全封装好的!!!复制到c#就可以用..具体测试你们自己来..希望收藏的人帮我三件事:rn一:帮我顶下帖.^_^.rn二:请大家也把自己经典的代码发到上面来共享..咱要开源开源...rn三:女友搞活动.希望各位帮我进去登个QQ投下票票!rnhttp://act.qzone.qq.com/kfc/detail.php?player=180413256rn 论坛

没有更多推荐了,返回首页