58
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 Cpf and cnpj masks depending on the number of characters typed. Here it doesn’t work totally well, because with several tests I did here, this my code didn’t work that I need. I don’t know if I should just change, or if I need to make another.
Follows 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.
Follow the tutorial
https://github.com/RobinHerbots/jquery.inputmask
and Cdnhttps://cdnjs.com/libraries/jquery.inputmask
see you around.– KingRider
Diego you saw my answer ?
– Matheus Miranda