Precisando de ajuda? Chame a Rede Superlar!

Envie uma mensagem
function aplicarMascaraTelefone(campo) { campo.addEventListener('input', function () { let numero = campo.value.replace(/\D/g, ''); if (numero.length > 11) numero = numero.slice(0, 11); if (numero.length > 6) { campo.value = `(${numero.slice(0, 2)}) ${numero.slice(2, 7)}-${numero.slice(7)}`; } else if (numero.length > 2) { campo.value = `(${numero.slice(0, 2)}) ${numero.slice(2)}`; } else if (numero.length > 0) { campo.value = `(${numero}`; } }); // Bloqueia colagens com letras/símbolos campo.addEventListener('paste', function (e) { e.preventDefault(); let texto = (e.clipboardData || window.clipboardData).getData('text'); texto = texto.replace(/\D/g, '').slice(0, 11); // só números document.execCommand('insertText', false, texto); }); // Bloqueia digitação de letras/símbolos campo.addEventListener('keypress', function (e) { const tecla = String.fromCharCode(e.which); if (!/[0-9]/.test(tecla)) { e.preventDefault(); } }); } document.addEventListener('DOMContentLoaded', function () { const campo = document.getElementById('form-field-field_d2765ee'); if (campo) aplicarMascaraTelefone(campo); });