Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>descobrindo os números verificadores</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
- <meta name="referrer" content="default" id="meta_referrer" />
- <style>
- body {
- font-family: Arial, Helvetica, sans-serif;
- background-color: #F2F5A9;
- font-size: 1em;
- }
- .div {
- position: absolute;
- background-color: #F7BE81;
- width: 90%;
- margin: 20px;
- padding: 10px 20px 20px 20px;
- border: 1px solid #ccc;
- }
- .button, .text {
- padding: 10px;
- text-align: center;
- }
- .text {
- width: 100px;
- }
- input[type="radio"] {
- -webkit-appearance: checkbox; /* Chrome, Safari, Opera */
- -moz-appearance: checkbox; /* Firefox */
- -ms-appearance: checkbox; /* not currently supported */
- }
- @media screen and (max-width: 480px) {
- .div {
- width: 78%;
- margin: 10px;
- }
- }
- </style>
- </head>
- <body>
- <br>
- <h3>
- <center>
- Descubra os dígitos verificadores e gere CPFs válidos
- </center></h3>
- <br>
- <center>
- <p>
- Digite os 9 números do cpf e descubra os dígitos verificadores
- </p>
- <input type="text" class="text" id="valorCpf" name="valorCpf" maxlength="9" autofocus onkeypress='return event.charCode >= 48 && event.charCode <= 57' />
- <input type="button" class="button" name="gerarValor"value="Descobrir" onclick="gerarCPF(document.getElementById('cpf'));" />
- <input type="reset" class="button" value="Limpar" onclick="limpa()" />
- <div class="div">
- <p>
- Pontuação
- </p>
- <label class="label_pontuacao" >
- <input type="radio" name="pontuacaoCpf" value="true" checked>
- Com pont.</label>
- <label class="label_pontuacao">
- <input type="radio" name="pontuacaoCpf" value="false">
- Sem pont.</label>
- <hr>
- <p>
- CPF completo
- </p>
- <input type="text" class="text" name="cpf" id="cpf" readonly="readonly"/>
- <p>
- <div id="estado">
- Mostra o estado do CPF aqui.
- </div>
- </center>
- </div>
- <script>
- function gerarCPF(field) {
- // Pega o nome do input radio que vai usar navariavel pontuacaoCpf
- var pontuacaoCpf = document.getElementsByName("pontuacaoCpf");
- // Faz a varredura nos inputs radio com o nome do documento escolhido acima
- for ( a = 0; a < pontuacaoCpf.length; a++) {
- // Ao encontrar o input radio marcado, pega o valor da id dele
- if (pontuacaoCpf[a].checked) {
- // Breca a varredura pelos inputs radio
- break;
- }
- }
- var numerosCpf = document.getElementById('valorCpf').value;
- if (numerosCpf != '000000000' &
- numerosCpf != '111111111' &
- numerosCpf != '222222222' &
- numerosCpf != '333333333' &
- numerosCpf != '444444444' &
- numerosCpf != '555555555' &
- numerosCpf != '666666666' &
- numerosCpf != '777777777' &
- numerosCpf != '888888888' &
- numerosCpf != '999999999')
- //numerosCpf != '123456789' &
- //numerosCpf != '987654321')
- {
- if (numerosCpf != '' && numerosCpf.length == 9) {
- var comPontos = pontuacaoCpf[a].value;
- var n = 9;
- var n1 = numerosCpf.substring(0, 1);
- var n2 = numerosCpf.substring(1, 2);
- var n3 = numerosCpf.substring(2, 3);
- var n4 = numerosCpf.substring(3, 4);
- var n5 = numerosCpf.substring(4, 5);
- var n6 = numerosCpf.substring(5, 6);
- var n7 = numerosCpf.substring(6, 7);
- var n8 = numerosCpf.substring(7, 8);
- var n9 = numerosCpf.substring(8, 9);
- if (n9 == 0) {
- document.getElementById('estado').innerHTML = "Rio Grande do Sul";
- } else if (n9 == 1) {
- document.getElementById('estado').innerHTML = "Distrito Federeal, Goiás, Mato Grosso do Sul e Tocantins";
- } else if (n9 == 2) {
- document.getElementById('estado').innerHTML = "Pará, Amazonas, Acre, Amapá, Rondônia e Roraima";
- } else if (n9 == 3) {
- document.getElementById('estado').innerHTML = "Ceará, Maranhão e Piauí";
- } else if (n9 == 4) {
- document.getElementById('estado').innerHTML = "Pernambuco, Rio Grande do Norte, Paraíba e Alagoas";
- } else if (n9 == 5) {
- document.getElementById('estado').innerHTML = "Bahia e Sergipe";
- } else if (n9 == 6) {
- document.getElementById('estado').innerHTML = "Minas Gerais";
- } else if (n9 == 7) {
- document.getElementById('estado').innerHTML = "Rio de Janeiro e Espírito Santo";
- } else if (n9 == 8) {
- document.getElementById('estado').innerHTML = "São Paulo";
- } else if (n9 == 9) {
- document.getElementById('estado').innerHTML = "Paraná e Santa Catarina";
- };
- var d1 = n9 * 2 + n8 * 3 + n7 * 4 + n6 * 5 + n5 * 6 + n4 * 7 + n3 * 8 + n2 * 9 + n1 * 10;
- d1 = 11 - ( mod(d1, 11) );
- if (d1 >= 10)
- d1 = 0;
- var d2 = d1 * 2 + n9 * 3 + n8 * 4 + n7 * 5 + n6 * 6 + n5 * 7 + n4 * 8 + n3 * 9 + n2 * 10 + n1 * 11;
- d2 = 11 - ( mod(d2, 11) );
- if (d2 >= 10)
- d2 = 0;
- retorno = '';
- if (comPontos == 'true')
- cpf = '' + n1 + n2 + n3 + '.' + n4 + n5 + n6 + '.' + n7 + n8 + n9 + '-' + d1 + d2;
- else
- cpf = '' + n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + d1 + d2;
- field.value = cpf;
- } else {
- document.getElementById('cpf').value = '';
- }
- } else {
- document.getElementById('valorCpf').value = '';
- document.getElementById('valorCpf').focus();
- document.getElementById('cpf').value = "";
- document.getElementById('estado').innerHTML = "Número para verificação inválido.";
- };
- }
- function randomiza(n) {
- var ranNum = Math.round(Math.random() * n);
- return ranNum;
- }
- function mod(dividendo, divisor) {
- return Math.round(dividendo - (Math.floor(dividendo / divisor) * divisor));
- }
- function limpa() {
- document.getElementById('valorCpf').value = "";
- document.getElementById('cpf').value = "";
- document.getElementById('valorCpf').focus();
- document.getElementById('estado').innerHTML = "Mostra o estado do CPF aqui.";
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement