Skip to content

Instantly share code, notes, and snippets.

@cristoferdomingues
Forked from igorcosta/cpf_cnpj_validator
Created March 16, 2018 20:17
Show Gist options
  • Save cristoferdomingues/0be786edf5fb4255d27f37c33bb7b2fb to your computer and use it in GitHub Desktop.
Save cristoferdomingues/0be786edf5fb4255d27f37c33bb7b2fb to your computer and use it in GitHub Desktop.
Regex para validar CPF e CNPJ
Para CPF
/^\d{3}\.\d{3}\.\d{3}\-\d{2}$/
Para CNPJ
/^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/
Para ambos ao mesmo tempo
/(^\d{3}\.\d{3}\.\d{3}\-\d{2}$)|(^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$)/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment