Skip to content

Instantly share code, notes, and snippets.

@danielfilho
Forked from erikhenrique/bin-cc.md
Last active June 28, 2018 16:13
Show Gist options
  • Save danielfilho/9cd8fb61a39778be587c to your computer and use it in GitHub Desktop.
Save danielfilho/9cd8fb61a39778be587c to your computer and use it in GitHub Desktop.

Validação para cartão de crédito.

Bin e padrões para validação de cartão de crédito.

Bandeira Comeca com Máximo de número Máximo de número cvc
Visa 4 13,16 3
Mastercard 5 16 3
Diners 301,305,36,38 14,16 3
Elo 636368, 438935, 504175, 451416, 636297,5067,4576,4011 16 3
Amex 34,37 15 4
Discover 6011,622,64,65 16 4
Aura 50 16 3
jcb 35 16 3
Hipercard 38,60 13,16,19 3

Validation for credit cards

var ccPatterns = {
  "visa": "^4[0-9]{12}(?:[0-9]{3})?$",
  "mastercard": "^5[1-5][0-9]{14}$",
  "amex": "^3[47][0-9]{13}$",
  "jcb": "^(?:2131|1800|35\d{3})\d{11}$",
  "diners_club": "^3(?:0[0-5]|[68][0-9])[0-9]{11}$",
  "elo": "/^([6362]{4})([0-9]{12})$/",
  "hipercard": "/^(3841\d{10}(\d{3})?)|(3841\d{15})$/"
};

Explanation:

  • Visa card numbers start with a 4. New cards have 16 digits. Old cards have 13.
  • MasterCard numbers start with the numbers 51 through 55. All have 16 digits.
  • American Express (amex) card numbers start with 34 or 37 and have 15 digits
  • JCB cards beginning with 2131 or 1800 have 15 digits. JCB cards beginning with 35 have 16 digits.
  • Diners Club card numbers begin with 300 through 305, 36 or 38. All have 14 digits. There are Diners Club cards that begin with 5 and have 16 digits. These are a joint venture between Diners Club and MasterCard, and should be processed like a MasterCard.
@jonatanrdsantos
Copy link

A regex que estou usando para o Aura por enquanto é: /^50[0-9]{17}$/, é o mesmo que a saraiva usa(andei bisbilhotando o checkout deles eheuehueheuu).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment