设年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('不匹配');