Hello, I looked for this doubt in the questions, but I could not find it. Well, I would like to make a field have the masks of cpf and cnpj depending on the amount of characters typed. This is not quite true, because with several tests I did here, my code did not work that I need. I do not know if I should just change, or if I need to do another one.
Follow the code:
$("#cpfcnpj").keypress(function(){
$("#cpfcnpj").unmask();
var tamanho = $("#cpfcnpj").val().length;
if(tamanho == 11){
$("#cpfcnpj").mask("999.999.99-99");
} else if(tamanho == 14){
$("#cpfcnpj").mask("99.999.999/9999-99");
}
});
Note: I'm using this plugin .