Skip to content

Instantly share code, notes, and snippets.

@waghcwb
Forked from igorcosta/cpf_cnpj_validator
Created August 28, 2017 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waghcwb/ad146b00a76df5444533bf8a24fc58e3 to your computer and use it in GitHub Desktop.
Save waghcwb/ad146b00a76df5444533bf8a24fc58e3 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