Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cpfCnpj(v) {
- //Remove tudo o que não é dígito
- v = v.replace(/\D/g, "")
- if (v.length <= 13) { //CPF
- v = v.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
- } else { //CNPJ
- v = v.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "$1.$2.$3/$4-$5");
- }
- return v
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement