Skip to content

Instantly share code, notes, and snippets.

View joaotanaca's full-sized avatar
:electron:
Working from home

Tanaca joaotanaca

:electron:
Working from home
View GitHub Profile
@joaotanaca
joaotanaca / maskCPFCNPJ.js
Last active July 10, 2021 05:22
Máscara de CPF e CNPJ
function maskCPF(element = new HTMLInputElement()) {
let cpfAtualizado;
const inputCpf = element;
const cpfAtual = element.value;
cpfAtualizado = cpfAtual.replace(
/(\d{3})(\d{3})(\d{3})(\d{2})/,
(_regex, one, two, three, four) => `${one}.${two}.${three}-${four}`,
);
inputCpf.value = cpfAtualizado;
return;