36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
// formatacoes.js
|
|
|
|
function formatarCPF(cpf) {
|
|
cpf = cpf.replace(/[^\d]/g, "");
|
|
return cpf.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
|
|
}
|
|
|
|
function formatarTelefone(telefone) {
|
|
telefone = telefone.replace(/[^\d]/g, "");
|
|
return telefone.replace(/(\d{2})(\d{5})(\d{4})/, "($1) $2-$3");
|
|
}
|
|
|
|
// Função para aplicar a formatação em uma tabela
|
|
function formatarTabela(tabelaSeletor, cpfColuna, telefoneColuna) {
|
|
$(tabelaSeletor + ' tr').each(function() {
|
|
var cpf = $(this).find('td:nth-child(' + cpfColuna + ')').text();
|
|
var telefone = $(this).find('td:nth-child(' + telefoneColuna + ')').text();
|
|
|
|
if (cpf) {
|
|
$(this).find('td:nth-child(' + cpfColuna + ')').text(formatarCPF(cpf));
|
|
}
|
|
|
|
if (telefone) {
|
|
$(this).find('td:nth-child(' + telefoneColuna + ')').text(formatarTelefone(telefone));
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// Função para aplicar a formatação em um elemento específico (client_details.php)
|
|
function formatarElemento(elementoSeletor, valor) {
|
|
if (valor) {
|
|
$(elementoSeletor).text(formatarTelefone(valor));
|
|
}
|
|
}
|