Regular expression to detect credit card flag

Asked

Viewed 52,381 times

55

I need Regex to detect when the credit card flag is Hipercard, Aura and Elo.

I already own regexes for Amex, Martercard, Diners Club, Visa, Discover and JCB:

Visa: ^4[0-9]{12}(?:[0-9]{3})
Mastercard: ^5[1-5][0-9]{14}
Amex: ^3[47][0-9]{13}
Diners Club: ^3(?:0[0-5]|[68][0-9])[0-9]{11}
Discover: ^6(?:011|5[0-9]{2})[0-9]{12}
JCB: ^(?:2131|1800|35\d{3})\d{11}
  • 3

    There is a free service that returns this information. See http://www.binlist.net/

5 answers

42


Credit card numbers follow an international standard called IEC-7812.

Basically, the first six digits of the card are Issuer Identifier number (IIN) (Issuer Identification Number).

So, you don’t need a regex, but a list of IIN with which you can check the number.

  • 3

    I think the regex that he wanted to talk about was the rule to use the IIN.

30

For those interested, follow a list of Bins:

| 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,509048,509067,  |                  | 3(?)
|            | 509049,509069,509050,509074,509068,509040,
|            | 509045,509051,509046,509066,509047,509042,
|            | 509052,509043,509064,509040                 |                  |                      
|            | 36297, 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                    |

https://gist.github.com/erikhenrique/5931368

  • your list of Elo numbers does not match the link or previous revisions of the link. Any reason? You have another source of these BIN?

  • 2

    Opa Gor, this ELO list I updated after receiving an email from moip with the new Elo Bins. Abcs

21

Link:

/^((((636368)|(438935)|(504175)|(451416)|(636297))\d{0,10})|((5067)|(4576)|(4011))\d{0,12})$/

Hypercard:

/^(606282\d{10}(\d{3})?)|(3841\d{15})$/

12

Hypercard:

/^(606282\d{10}(\d{3})?)|(3841\d{15})$/

4

For those who work with technologies based on nodejs and want a simpler way that addresses a large amount of cards recommend using the npm Credit Card Type to identify the flag of the card by its number.

Usage ES6 modules:

import creditCardType from 'credit-card-type'


creditCardType(cardNumber).filter((card) => {
  return card.type
})

Supported cards:

  • visa
  • Mastercard
  • American-express
  • Diners-club
  • Discover
  • Jcb
  • unionpay
  • conductor
  • Mir
  • link
  • hyper
  • hypercard

Browser other questions tagged

You are not signed in. Login or sign up in order to post.