https://github.com/cuducos/go-cnpf
🇧🇷 CPF and CNPJ validation in Go
https://github.com/cuducos/go-cnpf
brasil brazil cnpj cpf go hacktoberfest validation
Last synced: 2 months ago
JSON representation
🇧🇷 CPF and CNPJ validation in Go
- Host: GitHub
- URL: https://github.com/cuducos/go-cnpf
- Owner: cuducos
- License: bsd-3-clause
- Created: 2020-03-31T00:53:09.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-28T20:46:06.000Z (12 months ago)
- Last Synced: 2025-04-03T16:21:37.791Z (6 months ago)
- Topics: brasil, brazil, cnpj, cpf, go, hacktoberfest, validation
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 17
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Go CNPF []() [](https://godoc.org/github.com/cuducos/go-cnpf) 
A Go module to validate CPF and CNPJ numbers (Brazilian people and companies unique identifier for the Federal Revenue).
> The pseudo-acronym _CNPF_ is a sort of tong-twister and a common typo when developers discuss the implementation of objects that could hold either a CPF or a CNPJ numbers.
```go
package mainimport "github.com/cuducos/go-cnpf"
func main() {
// these return true
cnpf.IsValid("23858488135")
cnpf.IsValid("238.584.881-35")
cnpf.IsValid("11222333000181")
cnpf.IsValid("11.222.333/0001-81")
cnpj.IsValid("12.ABC.345/01DE-35")
cnpj.IsValid("12ABC34501DE35")// these return false
cnpf.IsValid("111.111.111-11")
cnpf.IsValid("11.111.111/1111-11")
cnpf.IsValid("123.456.769/01")
cnpf.IsValid("12.345.678 9012-34")
cnpf.IsValid("ABC.DEF.GHI-JK")
cnpf.IsValid("AB.CDE.FGH/IJKL-MN")
cnpf.IsValid("123")// these return 11111111111, 11111111111111 and 12ABC34501DE35
cnpf.Unmask("111.111.111-11")
cnpf.Unmask("11.111.111/1111-11")
cnpj.Unmask("12.ABC.345/01DE-35")// this return 111.111.111-11, 11.111.111/1111-11 and 12.ABC.345/01DE-35
cnpf.Mask("11111111111")
cnpf.Mask("11111111111111")
cnpj.Mask("12ABC34501DE35")
}
```
> [!IMPORTANT]
> Starting in July 2026 [the CNPJ number will be alphanumeric](https://www.gov.br/receitafederal/pt-br/acesso-a-informacao/acoes-e-programas/programas-e-atividades/cnpj-alfanumerico). This package **already supports the new format**. If you **do not** want to support the new format, tag this package to [`v0.0.1`](https://github.com/cuducos/go-cnpf/releases/tag/v0.0.1).Based on [Go CPF](https://github.com/cuducos/go-cpf) and [Go CNPJ](https://github.com/cuducos/go-cnpj) ❤️