Claudio51

Digite os números e descubra o CPF

Sep 23rd, 2021 (edited)
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 6.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <head>
  4.         <title>descobrindo os números verificadores</title>
  5.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  6.         <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  7.         <meta name="referrer" content="default" id="meta_referrer" />
  8.         <style>
  9.             body {
  10.                 font-family: Arial, Helvetica, sans-serif;
  11.                 background-color: #F2F5A9;
  12.                 font-size: 1em;
  13.             }
  14.             .div {
  15.                 position: absolute;
  16.                 background-color: #F7BE81;
  17.                 width: 90%;
  18.                 margin: 20px;
  19.                 padding: 10px 20px 20px 20px;
  20.                 border: 1px solid #ccc;
  21.             }
  22.             .button, .text {
  23.                 padding: 10px;
  24.                 text-align: center;
  25.             }
  26.             .text {
  27.                 width: 100px;
  28.             }
  29.             input[type="radio"] {
  30.                 -webkit-appearance: checkbox; /* Chrome, Safari, Opera */
  31.                 -moz-appearance: checkbox; /* Firefox */
  32.                 -ms-appearance: checkbox; /* not currently supported */
  33.             }
  34.             @media screen and (max-width: 480px) {
  35.                 .div {
  36.                     width: 78%;
  37.                     margin: 10px;
  38.                 }
  39.             }
  40.         </style>
  41.     </head>
  42.     <body>
  43.         <br>
  44.         <h3>
  45.         <center>
  46.             Descubra os dígitos verificadores e gere CPFs válidos
  47.         </center></h3>
  48.         <br>
  49.         <center>
  50.             <p>
  51.                 Digite os 9 números do cpf e descubra os dígitos verificadores
  52.             </p>
  53.             <input type="text" class="text" id="valorCpf" name="valorCpf" maxlength="9" autofocus onkeyup="gerarCPF(document.getElementById('cpf'))"  onkeypress='return event.charCode >= 48 && event.charCode <= 57' />
  54.             <!--<input type="button" class="button" name="gerarValor"value="Descobrir" onclick="gerarCPF(document.getElementById('cpf'));" />-->
  55.             <input type="reset" class="button" value="Limpar" onclick="limpa()" />
  56.  
  57.             <div class="div">
  58.                 <p>
  59.                     Pontuação
  60.                 </p>
  61.                 <label class="label_pontuacao" >
  62.                     <input type="radio" name="pontuacaoCpf" value="true" checked>
  63.                     Com pont.</label>
  64.                 <label class="label_pontuacao">
  65.                     <input type="radio" name="pontuacaoCpf" value="false">
  66.                     Sem pont.</label>
  67.                 <hr>
  68.                 <p>
  69.                     CPF completo
  70.                 </p>
  71.                 <input type="text" class="text" name="cpf" id="cpf" readonly="readonly"/>
  72.                 <p>
  73.                     <div id="estado">
  74.                         Mostra o estado do CPF aqui.
  75.                     </div>
  76.         </center>
  77.         </div>
  78.  
  79.         <script>
  80.             function gerarCPF(field) {
  81.                 // Pega o nome do input radio que vai usar navariavel pontuacaoCpf
  82.                 var pontuacaoCpf = document.getElementsByName("pontuacaoCpf");
  83.                 // Faz a varredura nos inputs radio com o nome do documento escolhido acima
  84.                 for ( a = 0; a < pontuacaoCpf.length; a++) {
  85.                     // Ao encontrar o input radio marcado, pega o valor da id dele
  86.                     if (pontuacaoCpf[a].checked) {
  87.                         // Breca a varredura pelos inputs radio
  88.                         break;
  89.                     }
  90.                 }
  91.                 var numerosCpf = document.getElementById('valorCpf').value;
  92.  
  93.                 if (numerosCpf != '000000000' &
  94.                     numerosCpf != '111111111' &
  95.                     numerosCpf != '222222222' &
  96.                     numerosCpf != '333333333' &
  97.                     numerosCpf != '444444444' &
  98.                     numerosCpf != '555555555' &
  99.                     numerosCpf != '666666666' &
  100.                     numerosCpf != '777777777' &
  101.                     numerosCpf != '888888888' &
  102.                     numerosCpf != '999999999')
  103.                     //numerosCpf != '123456789' &
  104.                     //numerosCpf != '987654321')
  105.                     {
  106.  
  107.                     if (numerosCpf != '' && numerosCpf.length == 9) {
  108.                         var comPontos = pontuacaoCpf[a].value;
  109.                         var n = 9;
  110.                         var n1 = numerosCpf.substring(0, 1);
  111.                         var n2 = numerosCpf.substring(1, 2);
  112.                         var n3 = numerosCpf.substring(2, 3);
  113.                         var n4 = numerosCpf.substring(3, 4);
  114.                         var n5 = numerosCpf.substring(4, 5);
  115.                         var n6 = numerosCpf.substring(5, 6);
  116.                         var n7 = numerosCpf.substring(6, 7);
  117.                         var n8 = numerosCpf.substring(7, 8);
  118.                         var n9 = numerosCpf.substring(8, 9);
  119.                        document.getElementById('cpf').focus();
  120.                         if (n9 == 0) {
  121.                             document.getElementById('estado').innerHTML = "Rio Grande do Sul";
  122.                            
  123.                         } else if (n9 == 1) {
  124.                             document.getElementById('estado').innerHTML = "Distrito Federeal, Goiás, Mato Grosso do Sul e Tocantins";
  125.                         } else if (n9 == 2) {
  126.                             document.getElementById('estado').innerHTML = "Pará, Amazonas, Acre, Amapá, Rondônia e Roraima";
  127.                         } else if (n9 == 3) {
  128.                             document.getElementById('estado').innerHTML = "Ceará, Maranhão e Piauí";
  129.                         } else if (n9 == 4) {
  130.                             document.getElementById('estado').innerHTML = "Pernambuco, Rio Grande do Norte, Paraíba e Alagoas";
  131.                         } else if (n9 == 5) {
  132.                             document.getElementById('estado').innerHTML = "Bahia e Sergipe";
  133.                         } else if (n9 == 6) {
  134.                             document.getElementById('estado').innerHTML = "Minas Gerais";
  135.                         } else if (n9 == 7) {
  136.                             document.getElementById('estado').innerHTML = "Rio de Janeiro e Espírito Santo";
  137.                         } else if (n9 == 8) {
  138.                             document.getElementById('estado').innerHTML = "São Paulo";
  139.                         } else if (n9 == 9) {
  140.                             document.getElementById('estado').innerHTML = "Paraná e Santa Catarina";
  141.                         };
  142.                        
  143.                         var d1 = n9 * 2 + n8 * 3 + n7 * 4 + n6 * 5 + n5 * 6 + n4 * 7 + n3 * 8 + n2 * 9 + n1 * 10;
  144.                         d1 = 11 - ( mod(d1, 11) );
  145.                         if (d1 >= 10)
  146.                             d1 = 0;
  147.                         var d2 = d1 * 2 + n9 * 3 + n8 * 4 + n7 * 5 + n6 * 6 + n5 * 7 + n4 * 8 + n3 * 9 + n2 * 10 + n1 * 11;
  148.                         d2 = 11 - ( mod(d2, 11) );
  149.                         if (d2 >= 10)
  150.                             d2 = 0;
  151.                         retorno = '';
  152.                         if (comPontos == 'true')
  153.                             cpf = '' + n1 + n2 + n3 + '.' + n4 + n5 + n6 + '.' + n7 + n8 + n9 + '-' + d1 + d2;
  154.                         else
  155.                             cpf = '' + n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9 + d1 + d2;
  156.                         field.value = cpf;
  157.                     } else {
  158.                         document.getElementById('cpf').value = '';
  159.                         document.getElementById('estado').innerHTML = "Mostra o estado do CPF aqui.";
  160.                
  161.                        
  162.                     }
  163.                 } else {
  164.                     document.getElementById('valorCpf').value = '';
  165.                     document.getElementById('valorCpf').focus();
  166.                     document.getElementById('cpf').value = "";
  167.                     document.getElementById('estado').innerHTML = "Número inválido.";
  168.                 };
  169.                
  170.             }
  171.  
  172.             function randomiza(n) {
  173.                 var ranNum = Math.round(Math.random() * n);
  174.                 return ranNum;
  175.             }
  176.  
  177.             function mod(dividendo, divisor) {
  178.                 return Math.round(dividendo - (Math.floor(dividendo / divisor) * divisor));
  179.             }
  180.  
  181.             function limpa() {
  182.                 document.getElementById('valorCpf').value = "";
  183.                 document.getElementById('cpf').value = "";
  184.                 document.getElementById('valorCpf').focus();
  185.                 document.getElementById('estado').innerHTML = "Mostra o estado do CPF aqui.";
  186.                
  187.             }
  188.  
  189.         </script>
  190.     </body>
  191. </html>
Add Comment
Please, Sign In to add comment