brdoc

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2018 License: Unlicense Imports: 2 Imported by: 15

README

BR Doc

Build Status GoDoc Go Report Card codecov

CPF, CNPJ, CEP validator for Go!

Everything in this file, but the To-do and License sections, 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, (e futuramente) CEP e RG. Este pacote possui apenas as funções individuais de validação. Para utilizar da integração com o govalidator, é necessário importar o pacote BR Doc Govalidator.

Uso

Principais funções:

  • func IsCPF(doc string) bool
  • func IsCNPJ(doc string) 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

// 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
To-do list
  • CPF validation
  • CNPJ validation
  • CEP validation
  • RG validation
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*.

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