Skip to content

Commit

Permalink
trim on cnpj call isValid
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagozs committed Nov 22, 2023
1 parent a09f89a commit e4b3391
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cnpj/cnpj.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (c *CNPJ) calculateCheckDigit(numbers []int) int {

// IsValidCNPJ validates a CNPJ
func (c *CNPJ) IsValid(cnpj string) bool {
cnpj = c.TrimCNPJ(cnpj)

if len(cnpj) != 14 {
return false
}
Expand Down
8 changes: 8 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ func main() {
}

println("Phone:", phone)

cnpj := "84.683.481/0776-33"

if utils.CNPJ().IsValid(utils.CNPJ().TrimCNPJ(cnpj)) {
println("CNPJ valid:", cnpj)
} else {
println("CNPJ INvalid:", cnpj)
}
}

0 comments on commit e4b3391

Please sign in to comment.