Remove Cpfs at the bottom of the Javascript page that validates CPF

Asked

Viewed 117 times

-1

I am using this script below to validate the CPF that was obtained from here. However, at the end of the form page, it will record the tested Cpfs in the footer. How to remove this function and leave only the validation?

function CPF() {
  "user_strict";

  function r(r) {
    for (
      var t = null, n = 0; 9 > n; ++n) t += r.toString().charAt(n) * (10 - n);
    var i = t % 11;
    return i = 2 > i ? 0 : 11 - i
  }

  function t(r) {
    for (
      var t = null, n = 0; 10 > n; ++n) t += r.toString().charAt(n) * (11 - n);
    var i = t % 11;
    return i = 2 > i ? 0 : 11 - i
  }
  var n = "CPF Inválido",
    i = "CPF Válido";
  this.gera =
    function() {
      for (
        var n = "", i = 0; 9 > i; ++i) n += Math.floor(9 * Math.random()) + "";
      var o = r(n),
        a = n + "-" + o + t(n + "" + o);
      return a
    }, this.valida =
    function(o) {
      for (
        var a = o.replace(/\D/g, ""), u = a.substring(0, 9), f = a.substring(9, 11), v = 0; 10 > v; v++)
        if ("" + u + f == "" + v + v + v + v + v + v + v + v + v + v + v)
          return n;
      var c = r(u),
        e = t(u + "" + c);
      return f.toString() === c.toString() + e.toString() ? i : n
    }
}
var CPF = new CPF();
document.write(CPF.valida("123.456.789-00"));
document.write("<br> Utilizando o proprio gerador da lib<br><br><br>");
for (var i = 0; i < 40; i++) {
  var temp_cpf = CPF.gera();
  document.write(temp_cpf + " = " + CPF.valida(temp_cpf) + "<br>");
}

$("#input").keypress(function() {
  $("#resposta").html(CPF.valida($(this).val()));
});

$("#input").blur(function() {
  $("#resposta").html(CPF.valida($(this).val()));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="input" name="input">
<div id="resposta"></div>

  • Remove $("#input"). keypress(Function(){ $("#response"). html(CPF.valida($(this). val()); }); $("#input"). Blur(Function(){ $("#response"). html(CPF.valida($(this). val()); });

  • 1

    Copied function from here :)

  • This question is being debated at the goal: http://meta.pt.stackoverflow.com/q/5769/132

1 answer

2

Remove the end of the script, that part:

$("#input").keypress(function(){
    $("#resposta").html(CPF.valida($(this).val()));
 });

$("#input").blur(function(){
    $("#resposta").html(CPF.valida($(this).val()));
}); 
  • That way it stops validating. So I commented on the "Document.write" lines and it stayed the way I needed it. thanks !!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.