Cpfcnpj
CPF and CNPJ - Validation package in Go
Install / Use
/learn @klassmann/CpfcnpjREADME
cpfcnpj
Brazilian taxpayer identification (CPF e CNPJ) - validation package in Golang.
It is an essential package for include validation for these numbers in your application.
Eg: It can be used in a payment system or account system.
Information about CPF and CNPJ
Installation
Use the go tool for do that:
$ go get github.com/klassmann/cpfcnpj
Usage
You need to import the package github.com/klassmann/cpfcnpj like that:
import (
"github.com/klassmann/cpfcnpj"
)
Example
package main
import (
"fmt"
"github.com/klassmann/cpfcnpj"
)
func main() {
// This will initialize a new CNPJ and clear the string
cnpj := cpfcnpj.NewCNPJ("70.082.591/0001-79")
// Verifies if it is a valid document
if !cnpj.IsValid() {
panic(fmt.Errorf("it is not a valid document: %v", cnpj))
}
// Cleaned output
fmt.Printf("%v\n", cnpj)
// Output: 70082591000179
// Formatted output
fmt.Println(cnpj.String())
// Output: 70.082.591/0001-79
}
Function: cpfcnpj.ValidateCPF(s string) bool
Validates the CPF document
import (
"fmt"
"github.com/klassmann/cpfcnpj"
)
/// CPF
func ValidatingCPF() {
r := cpfcnpj.ValidateCPF("71656686734")
if !r {
fmt.Printf("The document is invalid.")
}
}
Function: cpfcnpj.ValidateCNPJ(s string) bool
Validates the CNPJ document
/// CNPJ
func ValidatingCNPJ() {
r := cpfcnpj.ValidateCNPJ("64493884000146")
if !r {
fmt.Printf("The document is invalid.")
}
}
Function: cpfcnpj.Clean(s string) string
Clean the formatted document
cpf := cpfcnpj.Clean("111.222.333-99")
cnpj := cpfcnpj.Clean("10.963.268/0001-82")
License
Related Skills
node-connect
352.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
352.0kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
