EvaldoMaciel

Formantando CPF e CNPJ

Jul 2nd, 2021
1,333
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cpfCnpj(v) {
  2.     //Remove tudo o que não é dígito
  3.     v = v.replace(/\D/g, "")
  4.     if (v.length <= 13) { //CPF
  5.         v = v.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
  6.  
  7.     } else { //CNPJ
  8.         v = v.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "$1.$2.$3/$4-$5");
  9.     }
  10.     return v
  11. }
RAW Paste Data