Skip to content

silviucpp/erlcard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

erlcard

Build Status GitHub Hex.pm

Validates popular debit and credit cards numbers against regular expressions and Luhn algorithm. The library also validates the CVC code.

Installation

Add erlcard as a rebar or rebar3 dependency to your project:

{deps, [
  {erlcard, ".*", {git, "https://github.com/silviucpp/erlcard.git", "master"}},
}.

Usage

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).
Validate a card number knowing the type
{ok, <<"5500005555555559">>, mastercard} = erlcard:valid_credit_card(<<"5500005555555559">>, mastercard).
Validate a card number without knowing the type
{ok, <<"5500005555555559">>, mastercard} = erlcard:valid_credit_card(<<"5500005555555559">>).
Validate the CVC
true = erlcard:valid_cvc(<<"123">>, visa).

Tests

You can run the tests using make ct from root directory.