A correção do último dígito é calculada com base no número de identificação. Se estiver incorreto, o resultado correto será fornecido. É muito interessante quebrar o programa.
<! xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> title> javascript 18-digit <body Número <body Número <body) getIdchar18 (id) {var arr = id.split (''), sum = 0, vc = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 5, 8, 4, 2]; for (var i = 0; i <17; i ++) soma+= vc [i] * parseint (arr [i]); retornar ['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 ('o número de identificação de 18 dígitos que você inseriu está correto! caso contrário, o Showrst ('o número de identificação de 18 dígitos que você inseriu está incorreto, o código de verificação de 18 dígitos deve ser' + rc + '!'); } else showrst ('Por favor, insira o número de identificação de 18 dígitos para o número de identificação!'); } função showrst ('msg) {document.getElementById (' rst '). innerhtml = msg} </script> <input type = "text" onblur = "váldid (this.value)"/> <div id = "rst"> </div> </body> </html>