https://github.com/jfelipearaujo/cpfcnpj
Package responsible to check if a CPF or CNPJ is valid or not and generate valids CPF and CNPJ
https://github.com/jfelipearaujo/cpfcnpj
alphanumeric cnpj cpf generator golang valid validation
Last synced: 3 months ago
JSON representation
Package responsible to check if a CPF or CNPJ is valid or not and generate valids CPF and CNPJ
- Host: GitHub
- URL: https://github.com/jfelipearaujo/cpfcnpj
- Owner: jfelipearaujo
- License: mit
- Created: 2024-12-18T00:51:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-22T23:38:35.000Z (about 1 year ago)
- Last Synced: 2025-10-22T04:54:29.350Z (7 months ago)
- Topics: alphanumeric, cnpj, cpf, generator, golang, valid, validation
- Language: Go
- Homepage: https://jsfelipearaujo.com/
- Size: 43.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# cpfcnpj
[](https://github.com/jfelipearaujo/cpfcnpj/actions/workflows/ci.yml)
[](https://codecov.io/github/jfelipearaujo/cpfcnpj)
[](https://github.com/jfelipearaujo/cpfcnpj/releases/latest)
[](https://github.com/jfelipearaujo/cpfcnpj/blob/main/LICENSE)
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](https://www.gov.br/receitafederal/pt-br/acesso-a-informacao/acoes-e-programas/programas-e-atividades/cnpj-alfanumerico#:~:text=O%20CNPJ%20Alfanum%C3%A9rico%20ser%C3%A1%20atribu%C3%ADdo,com%20o%20seu%20n%C3%BAmero%20v%C3%A1lido!) for more information about the new format.
Download the package:
```bash
go get github.com/jfelipearaujo/cpfcnpj@latest
```
# How to use
- [cpfcnpj](#cpfcnpj)
- [How to use](#how-to-use)
- [Examples](#examples)
- [CPF Validation](#cpf-validation)
- [CNPJ Validation](#cnpj-validation)
- [CPF Generator](#cpf-generator)
- [CNPJ Generator](#cnpj-generator)
- [CNPJ Version](#cnpj-version)
- [Contributing](#contributing)
- [LICENSE](#license)
## Examples
You can find some examples in the [examples](examples) folder.
## CPF Validation
Import the package:
```go
import "github.com/jfelipearaujo/cpf"
```
Create a new instance of the service:
```go
svc := cpf.New()
```
Validate if the CPF is valid or not:
```go
err := svc.IsValid("123.456.789-10")
if err != nil {
// Handle invalid CPF
}
```
## CNPJ Validation
Import the package:
```go
import "github.com/jfelipearaujo/cpfcnpj/cnpj"
```
Create a new instance of the service:
```go
svc := cnpj.New()
```
Validate if the CNPJ is valid or not:
```go
err := svc.IsValid("12.ABC.345/01DE-35")
if err != nil {
// Handle invalid CNPJ
}
```
## CPF Generator
Import the package:
```go
import "github.com/jfelipearaujo/cpf"
```
Create a new instance of the service:
```go
svc := cpf.New()
```
Generate a new CPF:
```go
cpf := svc.Generate()
```
If you want to generate the CPF with pretty format, do the following:
```go
cpf := svc.Generate(cpf.WithPrettyFormat())
```
## CNPJ Generator
Import the package:
```go
import "github.com/jfelipearaujo/cpfcnpj/cnpj"
```
Create a new instance of the service:
```go
svc := cnpj.New()
```
Generate a new CNPJ:
```go
cnpj := svc.Generate()
```
If you want to generate the CNPJ with pretty format, do the following:
```go
cnpj := svc.Generate(cnpj.WithPrettyFormat())
```
### CNPJ Version
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:
```go
cnpj := svc.Generate(cnpj.WithVersion(cnpj.V2))
```
## Contributing
Contributions are welcome!
Please read the [CONTRIBUTING](CONTRIBUTING.md) file for details on our code of conduct, and the process for submitting pull requests.
## LICENSE
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.