//There should be an input box with the id identity_card on the HTML page, and a place to prompt a message when the ID card with the id ipmessage is incorrect or correct
<script> <br>//Identity Certificate verification <br>$(document).ready(function(){ <br>$("#identity_card").change(function(){ <br>var idcard =$(this).val(); <br>checkDate(idcard ); <br>}); <br>}); <br>//ID card<br>function checkDate( idcard ){ <br>var socialNo = idcard; <br>if(socialNo == "") <br>{ <br>$('#ipmessage').html('The format of the input ID number is incorrect, it must be a 15-digit to 18-digit ID number'); <br>alert("Enter ID number cannot be empty!"); <br>return (false); <br>} <br>if (socialNo.length != 15 && socialNo.length != 18) <br>{ <br>$( '#ipmessage').html('The format of the entered ID number is incorrect, it must be a 15- to 18-digit ID number'); <br>alert("The format of the entered ID number is incorrect!"); <br>return (false); <br>} <br>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:"Macau",91:"foreign"}; <br>if(area[parseInt(socialNo.substr(0,2))]==null ) { <br>$('#ipmessage').html('The format of the input ID number is incorrect, it must be a 15- to 18-digit ID number'); <br>alert("The ID number is incorrect ( Illegal in the region)!"); <br>return (false); <br>} <br>if (socialNo.length == 15) <br>{ <br>pattern= /^d{15}$/; <br>if (pattern.exec(socialNo)==null){ <br>$('#ipmessage').html('The format of the entered ID number is incorrect, it must be a 15-digit to 18-digit ID number') ; <br>alert("The 15-digit ID number must be numeric! "); <br>return (false); <br>} <br>var birth = parseInt("19" socialNo.substr(6,2)); <br>var month = socialNo.substr(8,2) ; <br>var day = parseInt(socialNo.substr(10,2)); <br>switch(month) { <br>case '01': <br>case '03': <br>case '05' : <br>case '07': <br>case '08': <br>case '10': <br>case '12': <br>if(day>31) { <br>$('# ipmessage').html('The format of the entered ID number is incorrect, it must be a 15- to 18-digit ID number'); <br>alert('The format of the entered ID number is incorrect!'); <br>return false; <br>} <br>break; <br>case '04': <br>case '06': <br>case '09': <br>case '11': <br>if(day> 30) { <br>$('#ipmessage').html('The format of the entered ID number is incorrect, it must be a 15- to 18-digit ID number'); <br>alert('The entered ID number is incorrect The format is correct!'); <br>return false; <br>} <br>break; <br>case '02': <br>if((birth % 4 == 0 && birth % 100 != 0) | | birth % 400 == 0) { <br>if(day>29) { <br>$('#ipmessage').html('The format of the input ID number is incorrect, it must be an identity of 15 to 18 digits ID number'); <br>alert('The format of the entered ID number is incorrect!'); <br>return false; <br>} <br>} else { <br>if(day>28) { <br>$('#ipmessage').html('The format of the entered ID number is incorrect, it must be a 15- to 18-digit ID number'); <br>alert('The format of the entered ID number is incorrect!') ; <br>return false; <br>} <br>} <br>break; <br>default: <br>$('#ipmessage').html('The format of the input ID number is incorrect, it must be 15 ID number to 18 digits'); <br>alert('The format of the entered ID number is not correct!'); <br>return false; <br>} <br>var nowYear = new Date().getYear (); <br>if(nowYear - parseInt(birth)<15 || nowYear - parseInt(birth)>100) { <br>$('#ipmessage').html('Enter the ID number format. Correct, it must be an ID number of 15 to 18 digits'); <br>alert('The format of the entered ID number is not correct!'); <br>return false; <br>} <br>$('# ipmessage').html('Passed! '); <br>return (true); <br>} <br>var Wi = new Array( <br>7,9,10,5,8,4,2,1,6, <br>3, 7,9,10,5,8,4,2,1 <br>); <br>var lSum = 0; <br>var nNum = 0; <br>var nCheckSum = 0; <br>for (i = 0; i < 17; i) <BR>{ <BR>if ( socialNo.charAt(i) < '0' || socialNo.charAt(i) > '9' ) <br>{ <br>$('#ipmessage').html('The format of the entered ID number is incorrect, it must be a 15- to 18-digit ID number'); <br>alert("The format of the entered ID number is incorrect!") ; <br>return (false); <br>} <br>else <br>{ <br>nNum = socialNo.charAt(i) - '0'; <br>} <br>lSum = nNum * Wi[ i]; <br>} <br>if( socialNo.charAt(17) == 'X' || socialNo.charAt(17) == 'x') <br>{ <br>lSum = 10*Wi[ 17]; <br>} <br>else if ( socialNo.charAt(17) < '0' || socialNo.charAt(17) > '9' ) <br>{ <br>$('#ipmessage ').html('The format of the entered ID number is incorrect, it must be a 15- to 18-digit ID number'); <br>alert("The format of the entered ID number is incorrect!"); <br>return ( false); <br>} <br>else <br>{ <br>lSum = ( socialNo.charAt(17) - '0' ) * Wi[17]; <br>} <br>if ( (lSum % 11) == 1 ) <br>{ <br>$('#ipmessage').html('Passed!'); <br>return true; <br>} <br>else <br>{ <br>$('#ipmessage').html('The format of the input ID number is incorrect, it must be 15 to 18 digits ID number'); <br>alert("The format of the entered ID number is incorrect!"); <br>return (false); <br>} <br>} <br></script>