Skip to content

Instantly share code, notes, and snippets.

@joseolinda
Last active August 21, 2019 18:40
Show Gist options
  • Save joseolinda/015b260bc4e388cd79adf2b09f785944 to your computer and use it in GitHub Desktop.
Save joseolinda/015b260bc4e388cd79adf2b09f785944 to your computer and use it in GitHub Desktop.
Mascarar CPF onBlur
const CPFInput = document.querySelector("#cpf");
CPFInput.addEventListener("blur", () => {
let CPFFormatado = CPFInput.value.replace( /^([\d]{3})([\d]{3})([\d]{3})([\d]{2})$/, "$1.$2.$3-$4");
CPFInput.value = CPFFormatado;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment