Regular expression to detect the credit card flag

52

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

I already have 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}
    
asked by anonymous 01.02.2014 / 12:18

5 answers

37

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

Basically, the first six digits of the card are the Issuer identifier number (IIN).

So you do not need a regex, but an IIN list with which you can check the number.

    
01.02.2014 / 13:06
26

Who cares, a list of BINs follows:

| 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                    |

link

    
22.05.2014 / 23:59
20

Link:

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

Hipercard:

/^(606282\d{10}(\d{3})?)|(3841\d{15})$/
    
03.06.2014 / 20:05
12

HiCard:

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

For those who wanted a simpler way to deal with a large number of cards, I recommend using the% Credit Card Type% Credit Card Type to identify the banner of the card by its number.

In ES6:

import creditCardType from 'credit-card-type'


creditCardType(cardDetail.number).filter((card) => {
  return card.type
})
    
20.11.2018 / 21:15