Skip to content

This Go package provides functions to validate Brazilian CPF and CNPJ numbers. The ValidateCPF function checks if a given string is a valid CPF number, and the ValidateCNPJ function checks if a given string is a valid CNPJ number. Both functions use weighted sum algorithms to calculate verification digits and validate the numbers against them.

License

Notifications You must be signed in to change notification settings

DanielFillol/Document

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brazilian Document Validation

This Go package provides functions to validate Brazilian CPF and CNPJ numbers. CPF (Cadastro de Pessoas Físicas) is a unique identification number given to Brazilian citizens, while CNPJ (Cadastro Nacional da Pessoa Jurídica) is a unique identification number given to Brazilian companies.

Installation

To use this package, you need to have Go installed on your computer. Then, open a terminal and run the following command:

go get github.com/DanielFillol/Document

Usage

Import the package into your code:

import "github.com/DanielFillol/Document"

ValidateCPF

The ValidateCPF function takes a string as input and returns a boolean value indicating whether the input is a valid CPF number. If the input is not a valid CPF number, the function returns false.

isValid := Document.ValidateCPF("123.456.789-09")

ValidateCNPJ

The ValidateCNPJ function takes a string as input and returns a boolean value indicating whether the input is a valid CNPJ number. If the input is not a valid CNPJ number, the function returns false.

isValid := Document.ValidateCNPJ("12.345.678/0001-00")

How it works

The validation process for both CPF and CNPJ numbers is based on a set of rules defined by the Brazilian government. The rules include checks for the number of digits, the format of the number, and the validity of the verification digits.

The verification digits are calculated using a weighted sum of the digits in the number, where each digit is multiplied by a specific weight. The resulting sum is then divided by a specific value, and the remainder is used to calculate the verification digit.

Contributing

If you find a bug or have a suggestion for improvement, please open an issue or submit a pull request on GitHub. We welcome contributions from the community.

About

This Go package provides functions to validate Brazilian CPF and CNPJ numbers. The ValidateCPF function checks if a given string is a valid CPF number, and the ValidateCNPJ function checks if a given string is a valid CNPJ number. Both functions use weighted sum algorithms to calculate verification digits and validate the numbers against them.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages