Boa tarde turma,
Alguém já fez alguma mascará de CNPJ/CPF no mesmo campo?
Muito obrigado.
Boa tarde turma,
Alguém já fez alguma mascará de CNPJ/CPF no mesmo campo?
Muito obrigado.
Criei essa function no custom.js
/**
* Mascara do campo - CPF/CNPJ, altera dinamicamente
* @param campo - Campos do Formulário
* @param teclapres - Tecla pressionada
* @returns {Boolean}
*/
function MascaraCpfCnpj(campo,teclapres) {
var tecla = teclapres.keyCode;
if ((tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && tecla != 46 && tecla != 8 && tecla != 9) {
return false;
}
var vr = campo.value;
vr = vr.replace( /\//g, "" );
vr = vr.replace( /-/g, "" );
vr = vr.replace( /\./g, "" );
var tam = vr.length;
if ( tam <= 2 ) {
campo.value = vr;
}
if ( (tam > 2) && (tam <= 5) ) {
campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam );
}
if ( (tam >= 6) && (tam <= 8) ) {
campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam );
}
if ( (tam >= 9) && (tam <= 11) ) {
campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam );
}
if ( (tam == 12) ) {
campo.value = vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam );
}
if ( (tam > 12) && (tam <= 14) ) {
campo.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam );
}
if (tam > 13){
if (tecla != 8){
return false
}
}
}
E no campo no formulário:
<div class="col-sm-4 col-xs-12">
<label for="CpfCnjpj">CPF/CNPJ</label>
<div class="form-field" data-type="textbox"
data-show-properties="" data-field-name="CpfCnjpj">
<input type="text"
class="form-control" name="A1CGC"
id="A1CGC" onkeydown="return MascaraCpfCnpj(this,event)"
onkeyup="return MascaraCpfCnpj(this,event)"
placeholder="Digite o CPF / CNPJ">
</div>
</div>
Fabio, você conseguiu resolver essa demanda?
— Brendo Santos 21 de Oct de 2019Really appreciate the insights shared in this thread! Forums like this are such a great resource for learning and exchanging ideas. On a related note, I came across https://offercatcher.com/ recently and found it super helpful for discovering deals and offers. Thought it might be worth sharing here. Excited to see more discussions from everyone!
— Offer catcher 3 weeks ago