As @iso8583-info-support implied in their comment, the only good way to do this is a BIN range lookup. A BIN is the first few digits of a card (technically, up to 6) which are issued in ranges to card issuers. So for example, Visa "owns" 4*
, so any card that starts with a 4
is a Visa card. MasterCard "owns" 2221*-2720*
and 51*-55*
, so any card which starts with a 51
, 52
, 53
, 54
, or 55
is a MasterCard, but a card which start with a 56
is not. (It's actually a Maestro card, which is a MasterCard sub-brand, but it's still technically separate - one's debit, the other is credit.) Anything unrecognized on a public BIN is almost certainly a loyalty card.
This can be a database table, but it doesn't have to be - you can easily hard code it into your app. But be sure to make it adjustable. MasterCard will start introducing card numbers which begin with a 2 in this coming October... if you can't modify your app to support that, you're going to annoy users.
This table on Wikipedia has all the major BIN ranges. There's also at least one company that sells an API which goes into far more detail and is kept much more up-to-date than Wikipedia.