Package responsible to check if a CPF or CNPJ is valid or not.
NOTE: This package is able to handle the new alphanumeric format of CNPJ that is expected to be used in Brazil from July 2026.
Click here for more information about the new format.
Download the package:
go get github.com/jfelipearaujo/cpfcnpj@latestYou can find some examples in the examples folder.
Import the package:
import "github.com/jfelipearaujo/cpf"Create a new instance of the service:
svc := cpf.New()Validate if the CPF is valid or not:
err := svc.IsValid("123.456.789-10")
if err != nil {
// Handle invalid CPF
}Import the package:
import "github.com/jfelipearaujo/cpfcnpj/cnpj"Create a new instance of the service:
svc := cnpj.New()Validate if the CNPJ is valid or not:
err := svc.IsValid("12.ABC.345/01DE-35")
if err != nil {
// Handle invalid CNPJ
}Import the package:
import "github.com/jfelipearaujo/cpf"Create a new instance of the service:
svc := cpf.New()Generate a new CPF:
cpf := svc.Generate()If you want to generate the CPF with pretty format, do the following:
cpf := svc.Generate(cpf.WithPrettyFormat())Import the package:
import "github.com/jfelipearaujo/cpfcnpj/cnpj"Create a new instance of the service:
svc := cnpj.New()Generate a new CNPJ:
cnpj := svc.Generate()If you want to generate the CNPJ with pretty format, do the following:
cnpj := svc.Generate(cnpj.WithPrettyFormat())This package is able to handle the new alphanumeric format of CNPJ that is expected to be used in Brazil from July 2026.
By default every CNPJ generate will use the V1 version with only numbers, but if you want to generate a CNPJ with the new version, do the following:
cnpj := svc.Generate(cnpj.WithVersion(cnpj.V2))Contributions are welcome!
Please read the CONTRIBUTING file for details on our code of conduct, and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.