Created
August 17, 2021 22:24
-
-
Save MoisesTedeschi/b83a8ff5750a01692b1d2624b238e90e to your computer and use it in GitHub Desktop.
Validador de CPF e/ou CNPJ com Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Com biblioteca: pip install pycpfcnpj | |
# https://github.com/matheuscas/pycpfcnpj | |
from pycpfcnpj import cpfcnpj | |
cpf_number = '11144477735' | |
masked_cpf_number = '111.444.777-35' | |
cnpj_number = '11444777000161' | |
masked_cnpj_number = '11.444.777/0001-61' | |
print cpfcnpj.validate(cpf_number) | |
print cpfcnpj.validate(masked_cpf_number) | |
print cpfcnpj.validate(cnpj_number) | |
print cpfcnpj.validate(masked_cnpj_number) | |
# Gerando CPF ou CNPJ | |
from pycpfcnpj import gen | |
gen.cpf() | |
gen.cnpj() | |
# Regex | |
''' | |
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