设年year、月month、身份证号code,已通过各种方式获取到
则
/** 确保参数为字符型 **/
year += '';
month += '';
code += '';if(code.length == 18) {
if(year.length == 4)
t = code.substr(6,6);
else {
t = code.substr(8,4)
year = year(2,2);
}
}else {
if(year.length == 4)
year = year(2,2);
t = code.substr(6,4);
}
if(t == year+month)
alert('匹配');
else
alert('不匹配');
则
/** 确保参数为字符型 **/
year += '';
month += '';
code += '';if(code.length == 18) {
if(year.length == 4)
t = code.substr(6,6);
else {
t = code.substr(8,4)
year = year(2,2);
}
}else {
if(year.length == 4)
year = year(2,2);
t = code.substr(6,4);
}
if(t == year+month)
alert('匹配');
else
alert('不匹配');
18位的身份证是从第7位开始取8位便是你的出生日期:年+月+日(全是8位数字)