Validates popular debit and credit cards numbers against regular expressions and Luhn algorithm. The library also validates the CVC code.
Add erlcard
as a rebar
or rebar3
dependency to your project:
{deps, [
{erlcard, ".*", {git, "https://github.com/silviucpp/erlcard.git", "master"}},
}.
All available types that can be validated are available in erlcard.hrl
:
-define(CARD_TYPE_AMEX, amex).
-define(CARD_TYPE_DANKORT, dankort).
-define(CARD_TYPE_DINERSCLUB, dinersclub).
-define(CARD_TYPE_DISCOVER, discover).
-define(CARD_TYPE_FORBRUGSFORENINGEN, forbrugsforeningen).
-define(CARD_TYPE_JCB, jcb).
-define(CARD_TYPE_MAESTRO, maestro).
-define(CARD_TYPE_MASTERCARD, mastercard).
-define(CARD_TYPE_UNIONPAY, unionpay).
-define(CARD_TYPE_VISA, visa).
-define(CARD_TYPE_VISAELECTRON, visaelectron).
{ok, <<"5500005555555559">>, mastercard} = erlcard:valid_credit_card(<<"5500005555555559">>, mastercard).
{ok, <<"5500005555555559">>, mastercard} = erlcard:valid_credit_card(<<"5500005555555559">>).
true = erlcard:valid_cvc(<<"123">>, visa).
You can run the tests using make ct
from root directory.