brdoc

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2018 License: Unlicense Imports: 4 Imported by: 0

README

BR Doc

Build Status GoDoc Go Report Card codecov

CPF, CNPJ and CEP validator for Go!

Everything in this file, but the License section, is in brazilian portuguese.

This package is also available in gopkg.in as Nhanderu/brdoc.v1.

Descrição

BR Doc é um pacote para validação, tanto do formato quanto dos dígitos, de documentos brasileiros, como CPF, CNPJ, CEP e (futuramente) RG.

Uso

Principais funções:

  • func IsCPF(doc string) bool
  • func IsCNPJ(doc string) bool
  • func IsCEP(doc string, ufs ...FederativeUnit) bool

Exemplo de valores válidos e inválidos:

// Inválidos por causa da inconsistência do dígito:
brdoc.IsCPF("248.438.034-99") //=> false
brdoc.IsCNPJ("26.637.142/0001-00") //=> false

// Inválidos por causa do formato:
brdoc.IsCPF("248 438 034 80") //=> false
brdoc.IsCNPJ("26637142-0001.58") //=> false
brdoc.IsCEP("01 001.001") //=> false

// Inválidos por causa da UF:
brdoc.IsCEP("01001-001", brdoc.RJ) //=> false

// Válidos:
brdoc.IsCPF("248.438.034-80") //=> true
brdoc.IsCPF("24843803480") //=> true
brdoc.IsCNPJ("26.637.142/0001-58") //=> true
brdoc.IsCNPJ("26637142000158") //=> true
brdoc.IsCEP("01001-001", brdoc.SP) //=> true
brdoc.IsCEP("01001001", brdoc.SP) //=> true

To-do list

  • validação de CPF
  • validação de CNPJ
  • validação de CEP
  • validação de RG

Validação de RG não foi implementado porque cada estado tem as suas regras e eu não estou com vontade de terminar isso. 💤

License

This project code is in the public domain. See the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCEP added in v1.1.0

func IsCEP(doc string, ufs ...FederativeUnit) bool

IsCEP verifies if `doc` is a valid CEP. `ufs` represents the possible Federative Units the CEP should matches. If none is provided, it validates the document for any state/district.

func IsCNPJ

func IsCNPJ(doc string) bool

IsCNPJ verifies if the string is a valid CNPJ document.

func IsCPF

func IsCPF(doc string) bool

IsCPF verifies if the string is a valid CPF document.

func ValidateCEPFormat added in v1.1.0

func ValidateCEPFormat(doc string) bool

ValidateCEPFormat verifies if the CEP has a valid format.

func ValidateCNPJFormat added in v1.1.1

func ValidateCNPJFormat(doc string) bool

ValidateCNPJFormat verifies if the CNPJ has a valid format.

func ValidateCPFFormat added in v1.1.1

func ValidateCPFFormat(doc string) bool

ValidateCPFFormat verifies if the CPF has a valid format.

Types

type FederativeUnit added in v1.1.0

type FederativeUnit uint8

FederativeUnit represents a state or a district in Brazil.

const (
	AC FederativeUnit = iota
	AL
	AP
	AM
	BA
	CE
	DF
	ES
	GO
	MA
	MT
	MS
	MG
	PA
	PB
	PR
	PE
	PI
	RJ
	RN
	RS
	RO
	RR
	SC
	SP
	SE
	TO
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL