3
someone can help me?
I have an input in which it is CPF/CNPJ, how do I make a mask containing two different values for the same field? And what would the code look like containing an additional phone field? In other words, it masks the Cpf/cnpj input and masks the phone, I only got it from Cpf, I can’t get it from the phone together!
<input type="text" name="cpf" id="cpf">
<input type="text" name="tel" id="tel">
$(document).ready(function(){
var SPMaskBehavior = function (val) {
return val.replace(/\D/g, '').length === 11 ? '000.000.000.00' : '00.000.000/0000-01';
},
spOptions = {
onKeyPress: function(val, e, field, options) {
field.mask(SPMaskBehavior.apply({}, arguments), options);
}
};
$('#cpf').mask(SPMaskBehavior, spOptions);
});
did not work, is not making the change of the mask when I type more than 11 digits to go to CNPJ, in fact it does not even let me type more than 11 digits, what can be @francisco
– Jean
@Jean Editei the answer, try agr.
– Francisco
now only in the mask of CNPJ :( @francisco
– Jean
what may be wrong @francisco http://jsfiddle.net/xpvt214o/133425/
– Jean
I changed the answer
– Francisco
perfect @francisco, the one from Cpf/cnpj worked right! I tried to adapt the code now for another need, but it is not working as at the beginning of Cpf. I have a fixed/cellular field... fixed follows the pattern (00) 1234-5678 already the cell has an extra digit in the first 5 decimal places (00) 12345-6789 as I can adapt the code, since I tried and did not work, see the masks as http://jsfiddle.net/xpvt214o/133983/
– Jean
@Jean Funcionando -> http://jsfiddle.net/3o5fbk5f/2/
– Francisco
Many thanks @francisco for your dedicated time!
– Jean
@Jean gives an upvote and marks the answer as correct pfv
– Francisco
hi @francisco went to implement the code of Cpf mask, however I saw that it is not working properly, the mask of Cpf is not correct, when you type the last digit of Cpf it already changes to cnpj mask, what can be? https://jsfiddle.net/1bt5k8mr/
– Jean
I edited the answer
– Francisco
now this perfect @francisco, mto thanks!
– Jean