Regular expression to detect credit card flag
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}
55
5 answers
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 don't need a regex, but a list of IIN with which you can check the number.
42
Author: motobói, 2014-02-01 14:28:41
Who is interested, follows 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 |
29
Author: Jefferson Silva, 2015-02-27 17:29:03
Elo:
/^((((636368)|(438935)|(504175)|(451416)|(636297))\d{0,10})|((5067)|(4576)|(4011))\d{0,12})$/
Hipercard:
/^(606282\d{10}(\d{3})?)|(3841\d{15})$/
20
Author: user3485590, 2014-06-04 18:47:54
HiperCard:
/^(606282\d{10}(\d{3})?)|(3841\d{15})$/
12
Author: Wellington, 2014-04-06 19:08:20
For those who work with technologies based on nodejs
and want a simpler way that addresses a large amount of Cards I recommend using the npm
Credit Card type to identify which card flag by its number.
Use ES6 modules:
import creditCardType from 'credit-card-type'
creditCardType(cardNumber).filter((card) => {
return card.type
})
Carões supported:
- visa
- mastercard
- american-express
- diners-club
- discover
- jcb
- unionpay
- Master
- mir
- elo
- hyper
- hipercard
4
Author: Marconi, 2019-07-15 13:57:26