The correctness of the last digit is calculated based on the ID number. If it is incorrect, the correct result will be given. It is very interesting to break the program.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>javascript 18-digit ID number last digit verification code</title></head><body><script> function getIDChar18(id) { var arr = id.split(''), sum = 0, vc = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; for (var i = 0; i < 17; i++) sum += vc[i] * parseInt(arr[i]); return ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'][sum % 11]; } function ValidID(id) { if (/^/d{18}$/.test(id)) { var c = id.charAt(17), rc = getIDChar18(id); if (c == rc) showRst('The 18-digit ID number you entered is correct!<br>Birthday:' + id.substr(6, 8) + '<br>Gender:' + ['Female', 'Male'][parseInt(id.charAt(16)) % 2]); else showRst('The 18-digit ID number you entered is incorrect, the 18-digit verification code should be ' + rc + '!'); } else showRst('Please enter the 18-digit ID number for ID number!'); } function showRst('msg) {document.getElementById('rst').innerHTML=msg }</script><input type="text" onblur="ValidID(this.value)" /><div id="rst"></div></body></html>