braintree / credit-card-type

A library for determining credit card type
MIT License
980 stars 154 forks source link

Replace regex with pattern arrays #81

Closed crookedneighbor closed 6 years ago

crookedneighbor commented 6 years ago

Thanks to ELO, the regex checking was getting ridiculously complicated. (and causing unexpected failures in card-validator https://github.com/braintree/card-validator/issues/64)

Instead, we can loop over bin patterns and eliminate redundancies by checking for a best match once the card number is long enough to determine the type conclusively (usually after 6 digits have been entered).

crookedneighbor commented 6 years ago

Correct, it is a major version bump. If we didn't allow people to add their own card types, it'd just be a minor version bump.