Last active
November 22, 2024 19:48
-
-
Save desenvolvendositeswp/db55ad3da4bfc6ecd5073e72bb383859 to your computer and use it in GitHub Desktop.
Mascara telefone 9 digitos + DD JetFormBuilder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Copie e cole no campo HTML do seu projeto*/ | |
document.addEventListener('DOMContentLoaded', function() { | |
const campoTelefone = document.querySelector('input[name="telefone"]'); // Substitua pelo nome do seu campo | |
if (campoTelefone) { | |
campoTelefone.addEventListener('input', function() { | |
let valor = this.value.replace(/\D/g, ''); // Remove tudo que não for número | |
if (valor.length <= 10) { | |
valor = valor.replace(/(\d{2})(\d{4})(\d{4})/, '($1) $2-$3'); // Formato (XX) XXXX-XXXX | |
} else { | |
valor = valor.replace(/(\d{2})(\d{5})(\d{4})/, '($1) $2-$3'); // Formato (XX) XXXXX-XXXX | |
} | |
this.value = valor; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment