jondavidjohn / payform

:credit_card: A library for building credit card forms, validating inputs, and formatting numbers.
https://jondavidjohn.github.io/payform/
Other
427 stars 81 forks source link

Update Mastercard BIN validation pattern #60

Closed ddayguerrero closed 5 years ago

ddayguerrero commented 5 years ago

According to page 73 of the official Mastercard Rules document:

The Corporation may assign BINs at its discretion from the following block ranges:

  • Mastercard: 222100 to 272099 and 510000 to 559999

Changes

While the previous validation regex for Mastercard surfaces the first 4-digits for the 2-series numbers and the first 2-digits for the 5-series numbers, it makes sense to strengthen the pattern and add support for the complete 6-digit number range.

I updated our regular expression so that it surfaces:

  1. 2-series MasterCard numbers 222100 to 272099
  2. 5-series MasterCard numbers 510000 to 559999

I also kept some of the edge case patterns that were part of the old regex (e.g. 677189)

How is this achieved?