All Projects → cuducos → go-cpf

cuducos / go-cpf

Licence: GPL-3.0 license
CPF validation in Go

Programming Languages

go
31211 projects - #10 most used programming language

Go CPF TestsGoDocGo version

A Go module to validate CPF numbers (Brazilian unique identifier for the Federal Revenue).

package main

import "github.com/cuducos/go-cpf"


func main() {
	// these return true
	cpf.IsValid("23858488135")
	cpf.IsValid("238.584.881-35")

	// these return false
	cpf.IsValid("111.111.111-11")
	cpf.IsValid("123.456.769/01")
	cpf.IsValid("ABC.DEF.GHI-JK")
	cpf.IsValid("123")

	// this returns 11111111111
	cpf.Unmask("111.111.111-11")

	// this returns 111.111.111-11
	cpf.Mask("11111111111")
}

I started to learn Go with Learn Go With Tests and this CPF (Brazilian unique identifier for the Federal Revenue) validation script is actually my very first lines in Go (except the ones from the book). I'm sharing it here to get feedback ❤️

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].