Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 2.55 KB

credit_card.md

File metadata and controls

62 lines (46 loc) · 2.55 KB

Credit Card Checker

The credit-card checker checks if the given value is a valid credit card number. If the given value is not a valid credit card number, the checker will return the NOT_CREDIT_CARD result.

Here is an example:

type Order struct {
    CreditCard string `checkers:"credit-card"`
}

order := &Order{
    CreditCard: invalidCard,
}

_, valid := checker.Check(order)
if valid {
  // Send the mistakes back to the user
}

The checker currently knows about AMEX, Diners, Discover, JCB, MasterCard, UnionPay, and VISA credit card numbers.

If you would like to check for a subset of those credit cards, you can specify them through the checker config parameter. Here is an example:

type Order struct {
    CreditCard string `checkers:"credit-card:amex,visa"`
}

order := &Order{
    CreditCard: "6011111111111117",
}

_, valid := checker.Check(order)
if valid {
  // Send the mistakes back to the user
}

If you would like to verify a credit card that is not listed here, please use the luhn checker to use the Luhn Algorithm to verify the check digit.

In your custom checkers, you can call the credit-card checker functions below to validate the user input.

Here is an example:

result := checker.IsAnyCreditCard("6011111111111117")

if result != checker.ResultValid {
  // Send the mistakes back to the user
}