La corrección del último dígito se calcula en función del número de identificación. Si es incorrecto, se dará el resultado correcto. Es muy interesante romper el programa.
< xmlns = "http://www.w3.org/1999/xhtml"> <fead> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> javaScript 18-digit Id Number Verification Code </bitle> </body> <calod <body> <scry> {var arr = id.split (''), sum = 0, VC = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; para (var i = 0; i <17; i ++) sum+= vc [i] * parseInt (arr [i]); return ['1', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2'] [suma % 11]; } function ValidId (id) {if (/^/d =18h}$/.test(id)) {var c = id.charat (17), rc = getIdchar18 (id); if (c == rc) showrst ('El número de identificación de 18 dígitos que ingresó es correcto! <br> cumpleaños:' + id.substr (6, 8) + '<br> género:' + ['femenino', 'masculino'] [parseint (id.charat (16)) % 2]); Else Showrst ('El número de identificación de 18 dígitos que ingresó es incorrecto, el código de verificación de 18 dígitos debe ser' + rc + '!'); } else showrst ('Ingrese el número de identificación de 18 dígitos para el número de identificación!'); } función showrst ('msg) {document.getElementById (' rst '). innerhtml = msg} </script> <input type = "text" onblur = "validid (this.value)"/> <div ID = "rst"> </div> </body> </html>