CPF and CNPJ Mask and Validator - Error

Asked

Viewed 333 times

0

Hi, I found a site where you mark and validate the CPF and CNPJ Link.

I’m testing, but it doesn’t seem to work. I’m doing it wrong or have some problem in the original code?

$(document).ready(function() {
  $('.validate').cpfcnpj({
    mask: true,
    validate: 'cpfcnpj',
    event: 'click',
    //validateOnlyFocus: true,
    handler: '.btn',
    ifValid: function(input) {
      input.removeClass("error");
      alert(returnType);
    },
    ifInvalid: function(input) {
      input.addClass("error");
      alert(returnType);
    }
  });
});
.error {
  border-color: #F70202
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://igorescobar.github.io/jQuery-Mask-Plugin/js/jquery.mask.min.js"></script>
<script src="https://github.com/gmgomess/jQuery-CPF-CNPJ-Validator-plugin/blob/master/jquery.cpfcnpj.js"></script>


<input type="text" class="validate" />
<input type="button" class="btn" value="Test" />

  • 1

    Yes it works, you need to download javascript for your machine and use it locally, it will run smoothly, the address does not work.

1 answer

2

You are trying to load the script from the Github repository address:

<script src="https://github.com/gmgomess/jQuery-CPF-CNPJ-Validator-plugin/blob/master/jquery.cpfcnpj.js"></script>

You need the file next to your project (side-by-side) or go up on some server.

For: Virgilio Novic

Browser other questions tagged

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