如何判断输入的身份证是否合法?

marquiswang 2001-11-27 04:08:59
如题!
...全文
202 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ragweed_wg 2001-11-29
  • 打赏
  • 举报
回复
可否考虑十八位身份证的最后一位可以是字母“X”,不信打电话给派出所……
webcool 2001-11-28
  • 打赏
  • 举报
回复
别忘了给分!!!!!
webcool 2001-11-28
  • 打赏
  • 举报
回复
//函数名:chkdate
//功能介绍:检查是否为日期
//参数说明:要检查的字符串
//返回值:0:不是日期 1:是日期
function chkdate(datestr)
{
var lthdatestr
if (datestr != "")
lthdatestr= datestr.length ;
else
lthdatestr=0;

var tmpy="";
var tmpm="";
var tmpd="";
//var datestr;
var status;
status=0;
if ( lthdatestr== 0)
return 0


for (i=0;i<lthdatestr;i++)
{ if (datestr.charAt(i)== '-')
{
status++;
}
if (status>2)
{
//alert("Invalid format of date!");
return 0;
}
if ((status==0) && (datestr.charAt(i)!='-'))
{
tmpy=tmpy+datestr.charAt(i)
}
if ((status==1) && (datestr.charAt(i)!='-'))
{
tmpm=tmpm+datestr.charAt(i)
}
if ((status==2) && (datestr.charAt(i)!='-'))
{
tmpd=tmpd+datestr.charAt(i)
}

}
year=new String (tmpy);
month=new String (tmpm);
day=new String (tmpd)
//tempdate= new String (year+month+day);
//alert(tempdate);
if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
{
//alert("Invalid format of date!");
return 0;
}
if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
{
//alert ("Invalid month or day!");
return 0;
}
if (!((year % 4)==0) && (month==2) && (day==29))
{
//alert ("This is not a leap year!");
return 0;
}
if ((month<=7) && ((month % 2)==0) && (day>=31))
{
//alert ("This month is a small month!");
return 0;

}
if ((month>=8) && ((month % 2)==1) && (day>=31))
{
//alert ("This month is a small month!");
return 0;
}
if ((month==2) && (day==30))
{
//alert("The Febryary never has this day!");
return 0;
}

return 1;
}
marquiswang 2001-11-28
  • 打赏
  • 举报
回复
chkdate()函数在吗?
webcool 2001-11-27
  • 打赏
  • 举报
回复
if (chkIdCard(s.id_card.value)==0){
alert("身份证号码位数错误!");
s.id_card.focus();
return false;
}
if (fucCheckNUM(s.id_card.value)==0){
alert("身份证号码应该为数字!");
s.id_card.focus();
return false;
}
if(s.id_card.value.length==15){
temp+="19"
for (i=6;i<12;i++){
if (i==8){temp+="-"}
if (i==10){temp+="-"}
temp+=s.id_card.value.charAt(i);
}
if (chkdate(temp)==0){
alert("身份证号码中所含的日期错误!");
s.id_card.focus();
return false;
}
}
if(s.id_card.value.length==18){
for (i=6;i<14;i++){
if (i==10){temp+="-"}
if (i==12){temp+="-"}
temp+=s.id_card.value.charAt(i);
}
if (chkdate(temp)==0){
alert("身份证号码中所含的日期错误!");
s.id_card.focus();
return false;
}
}
//===================================================================
//函数名:fucCheckNUM
//功能介绍:检查是否为数字
//参数说明:要检查的数字
//返回值:1为是数字,0为不是数字
function fucCheckNUM(NUM)
{
var i,j,strTemp;
strTemp="0123456789";
if ( NUM.length== 0)
return 0
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//说明有字符不是数字
return 0;
}
}
//说明是数字
return 1;
}
//=================================================================
//函数名:chkIdCard
//功能介绍:检查是否为身份证号码
//参数说明:要检查的字符串
//返回值:1为是身份证号码,0为不是身份证号码
function chkIdCard(s)
{
if(s.length!=15){
if(s.length!=18){
return 0;
}
else return 1;
}
else return 1;
}

87,992

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧