验证身份证
2014-10-09来源:易贤网

function isIdCardNo(num)

{

if (isNaN(num)) {alert("输入的不是数字!"); return false;}

var len = num.length, re;

if (len == 15)

re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);

else if (len == 18)

re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);

else {alert("输入的数字位数不对!"); return false;}

var a = num.match(re);

if (a != null)

{

if (len==15)

{

var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);

var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];

}

else

{

var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);

var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];

}

if (!B) {alert("输入的身份证号 "+ a[0] +" 里出生日期不对!"); return false;}

}

return true;

}

更多信息请查看IT技术专栏

2025公考·省考培训课程试听预约报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息