PawelDecowski / jquery-creditcardvalidator

jQuery credit card validation and detection plugin
jquerycreditcardvalidator.com
MIT License
1.06k stars 275 forks source link

Highlight both Visa types until Visa Electron is not possible #34

Open vipuldelwadia opened 10 years ago

vipuldelwadia commented 10 years ago

I think it shouldn't dim Visa Electron until you've typed enough of the number to rule it out (e.g. 40 could be either Visa). Via http://www.reddit.com/r/programming/comments/21uf5h/how_to_correctly_detect_credit_card_type/cggwbg1

PawelDecowski commented 10 years ago

Very good point. The behaviour will be changed in a future version. It will return null if the card number matches more than one card.

PawelDecowski commented 10 years ago

Another option is to return a list of cards that match, instead of null. That way you could, for example, highlight both Visa and Visa Electron until it’s clear which one it is. But it would be a breaking change — some implementations expect null if a single card hasn’t been matched.

A solution to that would be to return null by default, and provide an option to return a list of matched cards instead.

PawelDecowski commented 7 years ago

Actually, this can’t be done without introducing breaking changes.

For example, cards starting with 50 are Maestro cards. But cards starting with 5019 are Dankort. As you can see all Dankort cards will also match Maestro.

The way it’s solved currently, is the card ranges are sorted with more specific first: Dankort is more specific (5019) than Maestro (50) so it’s a match.

The only solution I can think of is to return a list of all matched cards. Then, you can decide how to present it in the UI (for example highlight all matched cards, or don’t highlight any until only 1 is matched).

The problem is this is a breaking change. The library historically returned only a single card — never a list — so granted, there is code out there that will break.

That’s why I’m putting it in for v2.0 for now.