feat: inputs de texto e tipos cpf/cnpj, telefone e tipos numericos inteiro e decimal

This commit is contained in:
andreLMpena 2025-12-22 14:00:44 -03:00
parent 454fddb061
commit 6c84508996
9 changed files with 454 additions and 23 deletions

View file

@ -0,0 +1,24 @@
function somenteNumeros(v: string): string {
return v.replace(/\D+/g, "");
}
export function formatarCpfCnpj(v: string): string {
const d = somenteNumeros(v);
// CPF
if (d.length <= 11) {
return d
.replace(/(\d{3})(\d)/, "$1.$2")
.replace(/(\d{3})(\d)/, "$1.$2")
.replace(/(\d{3})(\d{1,2})$/, "$1-$2")
.slice(0, 14);
}
// CNPJ
return d
.replace(/^(\d{2})(\d)/, "$1.$2")
.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3")
.replace(/\.(\d{3})(\d)/, ".$1/$2")
.replace(/(\d{4})(\d)/, "$1-$2")
.slice(0, 18);
}