Skip to content

Create or validate a Lühn (mod 10) check digit in a numeric string in Go.

License

Notifications You must be signed in to change notification settings

ferdypruis/go-luhn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-luhn

Build Status Go Reference

Create or validate a Lühn (mod 10) check digit in a numeric string in Go.

Examples

Checksum returns the Lühn check digit for number.

number := "7992739871"

checkdigit, _ := luhn.Checksum(number) // Ignoring error for simplicity
fmt.Println("The Lühn check digit for", number, "is", checkdigit)

// Output:
// The Lühn check digit for 7992739871 is 3

Sign returns number with its Lühn check digit appended

number := "7992739871"

number, _ = luhn.Sign(number) // Ignoring error for simplicity
fmt.Println("Your account number is", number)

// Output:
// Your account number is 79927398713

Valid returns whether number verifies against its appended check digit

number := "79927398713"

if luhn.Valid(number) {
    fmt.Println("The number is valid")
} else {
    fmt.Println("The number is not valid")
}

// Output:
// The number is valid

About

Create or validate a Lühn (mod 10) check digit in a numeric string in Go.

Topics

Resources

License

Stars

Watchers

Forks

Languages