Luhn (luhn60 v1.3.16)
Functions for validating Credit Card numbers using Luhn checksums.
Credit card numbers may be of arbitrary length and in arbitrary base.
Link to this section Summary
Functions
Compute and append the check digit for a given number.
Calculate the checksum of a number.
Compute the check digit of a number.
Evaluates a given credit card number for its validity, with an optionally provided base.
Link to this section Types
Link to this type
check_digit()
Specs
check_digit() :: non_neg_integer()
Link to this type
input()
Specs
Link to this section Functions
Link to this function
append_check_digit(n, base \\ 10)
Specs
append_check_digit(binary(), pos_integer()) :: binary()
Compute and append the check digit for a given number.
iex> Luhn.append_check_digit("7992739871")
"79927398713"
Link to this function
checksum(number, base \\ 10)
Specs
Calculate the checksum of a number.
This is known as the "mod 10" algorithm and the result will be zero if the check digit suffix is valid for the number.
iex> Luhn.checksum("79927398713")
0
Link to this function
compute_check_digit(n, base \\ 10)
Specs
compute_check_digit(input(), pos_integer()) :: check_digit()
Compute the check digit of a number.
iex> Luhn.compute_check_digit("7992739871")
3
iex> Luhn.compute_check_digit(7992739871)
3
Link to this function
valid?(number, base \\ 10)
Specs
Evaluates a given credit card number for its validity, with an optionally provided base.
# Accepts a string
iex(1)> Luhn.valid?("378282246310005")
true
# Or an integer
iex(2)> Luhn.valid?(378282246310005)
true
# Octal
iex(3)> Luhn.valid?("11111115", 8)
true
# Hexadecimal
iex(4)> Luhn.valid?("1580BB2EA887B", 16)
true