Luhn (luhn60 v1.3.3)
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
Calculate the checksum of a number.
Evaluates a given credit card number for its validity, with an optionally provided base.
Link to this section Functions
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
valid?(number, base \\ 10)
Specs
Evaluates a given credit card number for its validity, with an optionally provided base.
Examples
# Accepts a string
iex(1)> Luhn.valid?("378282246310005")
true
# Or an integer
iex(2)> Luhn.valid?(378282246310005)
true