SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <meta charset="utf-8">
  5.   <meta name="viewport" content="width=device-width">
  6.   <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. var cpf = [];
  12. var peso1 = [10,9,8,7,6,5,4,3,2];
  13. var peso2 = [11,10,9,8,7,6,5,4,3,2];
  14. var dv1; //primeiro digito calc.
  15. var dv2; //Segundo digito calc.
  16. var sum,resto;
  17.  
  18. var cpfu = prompt("Digite seu cpf sem . e -");
  19.  
  20. cpf[0] = Number(cpfu[0]);
  21. cpf[1] = Number(cpfu[1]);
  22. cpf[2] = Number(cpfu[2]);
  23. cpf[3] = Number(cpfu[3]);
  24. cpf[4] = Number(cpfu[4]);
  25. cpf[5] = Number(cpfu[5]);
  26. cpf[6] = Number(cpfu[6]);
  27. cpf[7] = Number(cpfu[7]);
  28. cpf[8] = Number(cpfu[8]);
  29. cpf[9] = Number(cpfu[9]);
  30. cpf[10] = Number(cpfu[10]);
  31.  
  32. sum =
  33. cpf[0]*peso1[0] + cpf[1]*peso1[1]+
  34. cpf[2]*peso1[2] + cpf[3]*peso1[3]+
  35. cpf[4]*peso1[4] + cpf[5]*peso1[5]+
  36. cpf[6]*peso1[6] + cpf[7]*peso1[7]+
  37. cpf[8]*peso1[8];
  38. resto = sum % 11;
  39. if(resto < 2){
  40.   dv1 = 0;
  41. }else{
  42.   dv1 = 11 - resto;
  43. }
  44. //dv2
  45. sum =
  46. cpf[0]*peso2[0] + cpf[1]*peso2[1]+
  47. cpf[2]*peso2[2] + cpf[3]*peso2[3]+
  48. cpf[4]*peso2[4] + cpf[5]*peso2[5]+
  49. cpf[6]*peso2[6] + cpf[7]*peso2[7]+
  50. cpf[8]*peso2[8] + cpf[9]*peso2[9];
  51. resto = sum % 11;
  52. if(resto < 2){
  53.   dv2 = 0;
  54. }else{
  55.   dv2 = 11 - resto;
  56. }
  57. if(dv1 == cpf[9] && dv2 == cpf[10
  58. ]){
  59. alert("CPF VALIDO");
  60. }else{
  61.   alert("CPF INVALIDO");
  62. }
  63. </script>
  64.  
  65.  
  66.  
  67. <script id="jsbin-source-javascript" type="text/javascript">var cpf = [];
  68. var peso1 = [10,9,8,7,6,5,4,3,2];
  69. var peso2 = [11,10,9,8,7,6,5,4,3,2];
  70. var dv1; //primeiro digito calc.
  71. var dv2; //Segundo digito calc.
  72. var sum,resto;
  73.  
  74. var cpfu = prompt("Digite seu cpf sem . e -");
  75.  
  76. cpf[0] = Number(cpfu[0]);
  77. cpf[1] = Number(cpfu[1]);
  78. cpf[2] = Number(cpfu[2]);
  79. cpf[3] = Number(cpfu[3]);
  80. cpf[4] = Number(cpfu[4]);
  81. cpf[5] = Number(cpfu[5]);
  82. cpf[6] = Number(cpfu[6]);
  83. cpf[7] = Number(cpfu[7]);
  84. cpf[8] = Number(cpfu[8]);
  85. cpf[9] = Number(cpfu[9]);
  86. cpf[10] = Number(cpfu[10]);
  87.  
  88. sum =
  89. cpf[0]*peso1[0] + cpf[1]*peso1[1]+
  90. cpf[2]*peso1[2] + cpf[3]*peso1[3]+
  91. cpf[4]*peso1[4] + cpf[5]*peso1[5]+
  92. cpf[6]*peso1[6] + cpf[7]*peso1[7]+
  93. cpf[8]*peso1[8];
  94. resto = sum % 11;
  95. if(resto < 2){
  96.   dv1 = 0;
  97. }else{
  98.   dv1 = 11 - resto;
  99. }
  100. //dv2
  101. sum =
  102. cpf[0]*peso2[0] + cpf[1]*peso2[1]+
  103. cpf[2]*peso2[2] + cpf[3]*peso2[3]+
  104. cpf[4]*peso2[4] + cpf[5]*peso2[5]+
  105. cpf[6]*peso2[6] + cpf[7]*peso2[7]+
  106. cpf[8]*peso2[8] + cpf[9]*peso2[9];
  107. resto = sum % 11;
  108. if(resto < 2){
  109.   dv2 = 0;
  110. }else{
  111.   dv2 = 11 - resto;
  112. }
  113. if(dv1 == cpf[9] && dv2 == cpf[10
  114. ]){
  115. alert("CPF VALIDO");
  116. }else{
  117.   alert("CPF INVALIDO");
  118. }</script></body>
  119. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top