Documentation
¶
Overview ¶
Package luhnmod10 is a fast and simple in-place implementation of the luhn check algorithm.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckDigit ¶
CheckDigit returns the check digit of a number string that can be used as the final digit to make a number string pass the luhnmod10 validity check. Use Valid to check if a number string is valid. The number passed to the function must contain only numeric characters otherwise behavior is undefined.
Example ¶
number := "424242424242424" checkDigit := luhnmod10.CheckDigit(number) fmt.Println(number, "check digit:", checkDigit)
Output: 424242424242424 check digit: 2
func Checksum ¶
Checksum returns the checksum of a number string that can be used to determine if the number satisfies the luhnmod10 validity check. Use Valid to check if a number string is valid. The number passed to the function must contain only numeric characters otherwise behavior is undefined.
Example ¶
number := "4242424242424241" checksum := luhnmod10.Checksum(number) fmt.Println(number, "checksum:", checksum)
Output: 4242424242424241 checksum: 79
func Valid ¶
Valid returns true if the number string is luhn valid, and false otherwise. The number passed to the function must contain only numeric characters otherwise behavior is undefined.
Example (False) ¶
number := "4242424242424241" valid := luhnmod10.Valid(number) fmt.Println(number, "is valid:", valid)
Output: 4242424242424241 is valid: false
Example (True) ¶
number := "4242424242424242" valid := luhnmod10.Valid(number) fmt.Println(number, "is valid:", valid)
Output: 4242424242424242 is valid: true
Types ¶
This section is empty.