Luhn

hex.pm versionhex.pm downloadsCI

Luhn algorithm implementation in Elixir for validating credit card numbers, IMEI numbers, and other identification numbers that use the Luhn checksum.

Supports arbitrary bases (decimal, hexadecimal, etc.).

Installation

Add luhn to your list of dependencies in mix.exs:

def deps do
  [
    {:luhn, "~> 0.3"}
  ]
end

Usage

# Validate a credit card number (string)
Luhn.valid?("378282246310005")
# => true

# Also works with integers
Luhn.valid?(4111111111111111)
# => true

# Hexadecimal support
Luhn.valid?("abc1239", 16)
# => true

# Get the checksum value
Luhn.checksum("378282246310005")
# => 0

Documentation

Full documentation is available on HexDocs.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT — see LICENSE for details.