This article mainly introduces the JS identification method to support 15-bit and 18-bit, the need for friends can refer to the following
The code is as follows: The//html page should have an input input box with an ID of Identity_card, a ipmessage ID error or a message where it is correct <script> //ID card Verification $ (document). Ready (function () { $ ("#identity_card"). Change (function () { var idcard =$ (This). Val (); Checkdate (Idcard); }); }); //ID function checkdate (idcard) { var socialno = Idcard ; if (Socialno = = "") { $ (' #ipmessage '). HTML (' Enter the ID number format incorrectly, must be 15 to 18-bit ID number '); alert (" Enter ID number cannot be empty! "); Return (false); } if (socialno.length!= && socialno.length!=) { $ (' #ipmessa GE '). html (' input ID number format is not correct, must be 15 to 18-bit ID number '); alert ("Input ID number format incorrect!"); Return (false); } var area={11: "Beijing", 12: "Tianjin", 13: "Hebei", 14: "Shanxi", 15: "Inner Mongolia", 21: "Liaoning", 22: "Jilin", 23: "Heilongjiang", 31 : "Shanghai", 32: "Jiangsu", 33: "Zhejiang", 34: "Anhui", 35: "Fujian", 36: "Jiangxi", 37: "Shandong", 41: "Henan", 42: "Hubei", 43: "Hunan", 44: "Guangdong", 45: "Guangxi", 46: "Hainan", 50: "Chongqing", 51: "Sichuan", 52: "Guizhou", 53: "Yunnan", 54: "Tibet", 61: "Shaanxi", 62: "Gansu", 63: "Qinghai", 64: "Ningxia", 65: "Xinjiang", 71: "Taiwan", 81: "Hong Kong", 82: "Macao", 91: "Foreign"}; if (Area[parseint (Socialno.substr (0,2))]==null) { $ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number '); Alert ("Incorrect ID number (illegal area)"); Return (false); } if (socialno.length =) { pattern=/^d{15}$/; if (pattern.exec (s Ocialno) ==null) { $ (' #ipmessage '). HTML (' input ID number format is incorrect, must be 15 to 18-bit ID number '); alert ("15 ID number must be number!") "); return (false); } var birth = parseint (" + socialno.substr (6,2)); var month = Socialno.subs TR (8,2); var day = parseint (Socialno.substr (10,2)); switch (month) { case ' the ': case ': C ASE ': case ' a ': case ' in ': case ' a ': case ': $ (' #ipmessage '). HTML (' input ID number format is not correct, must be 15 to 18-bit ID number '); alert (' Input ID number not formatted correctly! '); Return false; } break; case ': ' the case ': ' the case ': ' the case ' one ': if (day >30) { $ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number '); alERT (' Input ID number is not properly formatted! '); Return false; } break; case ': if (birth% 4 = 0 && Birth%!= 0) | | birth % = = 0) { if (day>29) { $ (' #ipmessage '). HTML (' Enter the ID number format incorrectly, must be 15 to 18-bit ID number '); alert (' Input ID number not formatted correctly! '); return false; } } else { if (day>28) { $ (' #ipmessage '). HTML (' input ID number is not in the correct format, Must be 15 to 18-bit ID number '); alert (' Input ID number not formatted correctly! '); return false; } } break; default: $ (' #ipmessage '). HTML (' input ID number is not in the correct format, Must be 15 to 18-bit ID number '); alert (' Input ID number not formatted correctly! '); return false; } var nowyear = new Date (). getyear (); if (Nowyear-parseint (birth) <15 | | nowyear -parseint (birth) >100) { $ (' #ipmessage '). HTML (' input ID number format incorrect, must be 15 to 18-bit ID number '); alert (' Input ID number not formatted correctly! '); Return false; } $ (' #ipmessage '). HTML (' Pass! '); return (true); } var Wi = new Array ( 7,9,10,5,8,4,2,1,6, 3,7,9,10,5,8,4,2,1 ); &nb Sp; var lsum = 0; var nnum = 0; var nchecksum = 0; for (i = 0; i < ++i) { if (socialno.c Harat (i) < ' 0 ' | | Socialno.charat (i) > ' 9 ') { $ (' #ipmessage '). HTML (' Enter the ID number format incorrectly, must be 15 to 18-bit ID number '); alert (" Input ID number format is not correct! "); Return (false); } else { nnum = Socialno.charat (i)-' 0 '; } lsum + + nnum * wi[i ]; } if (socialno.charat) = = ' X ' | | Socialno.charat (+) = ' x ') { lsum = 10*wi[17]; }&nb Sp else if (Socialno.charat < ' 0 ' | | socialno.charat (s) > ' 9 ') { $ (' #ipmessage '). HTML (' input ID number format is incorrect, Must be 15 to 18-bit ID number '); alert ("Input ID number format is not correct!"); Return (false); } else { lsum + + (socialno.charat)-' 0 ') * wi[17]; } if ( (lsum%) = = 1) { $ (' #ipmessage '). HTML (' Pass! '); return true; } else { $ (' #ipmessage '). HTML (' input ID number format is incorrect, must be 15 to 18-bit ID number '); Alert ("Enter the ID numberCode format is not correct! "); Return (false); } } </script>