项目作者: cuducos

项目描述 :
🇧🇷 CPF and CNPJ validation in Go
高级语言: Go
项目地址: git://github.com/cuducos/go-cnpf.git
创建时间: 2020-03-31T00:53:09Z
项目社区:https://github.com/cuducos/go-cnpf

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Go CNPF Tests GoDoc Go version

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.

  1. package main
  2. import "github.com/cuducos/go-cnpf"
  3. func main() {
  4. // these return true
  5. cnpf.IsValid("23858488135")
  6. cnpf.IsValid("238.584.881-35")
  7. cnpf.IsValid("11222333000181")
  8. cnpf.IsValid("11.222.333/0001-81")
  9. cnpj.IsValid("12.ABC.345/01DE-35")
  10. cnpj.IsValid("12ABC34501DE35")
  11. // these return false
  12. cnpf.IsValid("111.111.111-11")
  13. cnpf.IsValid("11.111.111/1111-11")
  14. cnpf.IsValid("123.456.769/01")
  15. cnpf.IsValid("12.345.678 9012-34")
  16. cnpf.IsValid("ABC.DEF.GHI-JK")
  17. cnpf.IsValid("AB.CDE.FGH/IJKL-MN")
  18. cnpf.IsValid("123")
  19. // these return 11111111111, 11111111111111 and 12ABC34501DE35
  20. cnpf.Unmask("111.111.111-11")
  21. cnpf.Unmask("11.111.111/1111-11")
  22. cnpj.Unmask("12.ABC.345/01DE-35")
  23. // this return 111.111.111-11, 11.111.111/1111-11 and 12.ABC.345/01DE-35
  24. cnpf.Mask("11111111111")
  25. cnpf.Mask("11111111111111")
  26. cnpj.Mask("12ABC34501DE35")
  27. }

[!IMPORTANT]
Starting in July 2026 the CNPJ number will be alphanumeric. This package already supports the new format. If you do not want to support the new format, tag this package to v0.0.1.

Based on Go CPF and Go CNPJ ❤️