brdoc

package module
v2.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Unlicense Imports: 5 Imported by: 0

README

BR Doc

License go.dev Travis CI Codecov.io Go Report Card

CPF, CNPJ, CEP, CNH, PIS/PASEP, RENAVAM, CNS and license plate validator for Go!

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

Descrição

BR Doc é um pacote para validação, tanto do formato quanto dos dígitos, de documentos brasileiros, como CPF, CNPJ, CEP, CNH, PIS/PASEP, RENAVAM, placa veicular e RG no padrão SP e RJ (futuramente demais padrões).

Aceito PRs de todas as formas. Está permitido escrever em português, também. :)

Uso

Principais funções:

  • func IsCPF(doc string) bool
  • func IsCNPJ(doc string) bool
  • func IsCEP(doc string, ufs ...FederativeUnit) bool
  • func IsCNH(doc string) bool
  • func IsPIS(doc string) bool
  • func IsRENAVAM(doc string) bool
  • func IsPlate(doc string) bool
  • func IsNationalPlate(doc string) bool
  • func IsMercosulPlate(doc string) bool
  • func IsCNS(doc string) bool
  • func IsRG(doc string) bool

Coisas a fazer

  • validação de CPF
  • validação de CNPJ
  • validação de CEP
  • validação de CNH (obrigado @eminetto!)
  • validação de RENAVAM (obrigado @leogregianin!)
  • validação de placa veicular
  • validação de CNS (obrigado @renatosuero!)
  • validação de RG
    • SP (obrigado @robas!)
    • RJ (obrigado @robas!)
    • demais estados

License

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

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be in the public domain, without any additional terms or conditions.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CPFRegexp  = regexp.MustCompile(`^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$`)
	CNPJRegexp = regexp.MustCompile(`^\d{2}\.?\d{3}\.?\d{3}\/?(:?\d{3}[1-9]|\d{2}[1-9]\d|\d[1-9]\d{2}|[1-9]\d{3})-?\d{2}$`)
)

Regexp pattern for CPF and CNPJ.

View Source
var (
	NationalPlateRegexp = regexp.MustCompile(`^[A-Z]{3}-?\d{4}$`)
	MercosulPlateRegexp = regexp.MustCompile(`^[A-Z]{3}\d[A-Z]\d{2}$`)
)

Regexp pattern for license plates patterns.

View Source
var (
	CEPRegexp = regexp.MustCompile(`^\d{5}-?\d{3}$`)
)

Regexp pattern for CEP.

View Source
var (
	CNSRegexp = regexp.MustCompile(`^([12]\d{2}\s?\d{4}\s?\d{4}\s?00[01]\d|[789]\d{2}\s?\d{4}\s?\d{4}\s?\d{4})$`)
)

Regexp pattern for CNS.

View Source
var (
	PISRegexp = regexp.MustCompile(`^\d{3}\.?\d{3,5}\.?\d{2,4}-?\d$`)
)

Regexp pattern for PIS.

Functions

func IsCEP

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 IsCNH

func IsCNH(doc string) bool

IsCNH verifies if the given string is a valid CNH document.

func IsCNPJ

func IsCNPJ(doc string) bool

IsCNPJ verifies if the given string is a valid CNPJ document.

func IsCNS

func IsCNS(doc string) bool

IsCNS verifies if the given string is a valid CNS document.

func IsCPF

func IsCPF(doc string) bool

IsCPF verifies if the given string is a valid CPF document.

func IsMercosulPlate

func IsMercosulPlate(doc string) bool

IsMercosulPlate verifies if the given string is a valid license plate in the new Mercosul format.

func IsNationalPlate

func IsNationalPlate(doc string) bool

IsNationalPlate verifies if the given string is a valid license plate in the old national format.

func IsPIS added in v2.3.3

func IsPIS(doc string) bool

IsPIS verifies if the given string is a valid PIS number.

func IsPlate

func IsPlate(doc string) bool

IsPlate verifies if the given string is a valid license plate.IsPlate It can be either in the old national format or the new Mercosul one.

func IsRENAVAM

func IsRENAVAM(doc string) bool

IsRENAVAM verifies if the given string is a valid RENAVAM document.

func IsRG added in v2.3.3

func IsRG(doc string, uf FederativeUnit) (isValid bool, err error)

IsRG verifies if `doc` is a valid RG. `uf` represents the Federative Unit the RG belongs to. Currently, the only implemented UFs are the following (the remaining will return an error):

  • SP
  • RJ

Types

type FederativeUnit

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
)

Federative unit for CEP validation.

Jump to

Keyboard shortcuts

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