AuricSystemsInternational/creditcard-validator/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

CreditCardValidator

This library allows validation of a creditcard number potentially limiting by accepted card types. For example, if your business only accepts Mastercard and Visa you can limit the valid cards to those types.

Definition

= AM
| DS
| MC
| VI
| DC
| UK

Card types supported by this library are: American Express (AM), Discover (DS), Diners Club (DC), Mastercard (MC) and VISA (VI).

type alias CardTypeInfo =
{ name : String
, cardType : CardType
, bins : List Range
, valid_lengths : List Int
}
type alias CreditCardNumber =
String
type alias ValidationResult =
{ card_types : List (Maybe CardTypeInfo)
, valid : Bool
, luhn_valid : Bool
, length_valid : Bool
, cardTypeValid : Bool
}

A card number can match multiple card types. Overall, a number is valid when it's valid according to luhn algorithm with valid length and type.

type Range

Represents possible ranges for a creditcard number. It can be a string or a range with starting and ending digits

Validation

validate : String -> List CardType -> ValidationResult

Find whether a creditcard number is valid. You can limit what card types are eligible for the validation attempt.

Helpers

mopToCardType : String -> CardType

Converts from string MOP (Method of Payment) to CardType

validCardLength : CardTypeInfo -> CreditCardNumber -> Bool

Finds whether card length is one of the valid lengths for the type

findNumberInBetweenRange : CreditCardNumber -> String -> String -> Bool
allCardTypes : List CardTypeInfo

List of CardTypeInfo for all supported types

cardTypeByBinRange : CreditCardNumber -> List CardTypeInfo -> Maybe CardTypeInfo

Find card info whose ranges contain a pattern that the card number matches

numberInStartsWithRange : String -> String -> Bool
cardMatchesRange : CreditCardNumber -> List Range -> Bool
filterByCardTypes : List CardTypeInfo -> List CardType -> List CardTypeInfo
toCleanCCNumber : String -> CreditCardNumber