Skip to content

Commit

Permalink
Merge pull request #37 from fluidpay/update-regex
Browse files Browse the repository at this point in the history
Update regex to support 19 digit cards
  • Loading branch information
bvoelker authored Dec 15, 2020
2 parents fdcd5ef + 5400a50 commit 48c8420
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 76 deletions.
6 changes: 3 additions & 3 deletions payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var (
amexCardFormatString = "^3[47][0-9]{13}$"
visaCardFormatString = "^4[0-9]{15}$"
mastercardCardFormatString = "^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$"
discoverCardFormatString = "^65[0-9]{14}|64[4-9][0-9]{13}|6011[0-9]{12}|(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10})$"
jcbCardFormatString = "^(?:2131|1800|35[0-9]{3})[0-9]{11}$"
dinersClubInternationalFormatString = "^3(?:0[0-5]|[68][0-9])[0-9]{11}$"
discoverCardFormatString = "^65[0-9]{14,17}|64[4-9][0-9]{13,16}|6011[0-9]{12,15}|(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10,13})$"
jcbCardFormatString = "^(?:2131|1800|35[0-9]{2})[0-9]{12,15}$"
dinersClubInternationalFormatString = "^3(?:0[0-5]|[68][0-9])[0-9]{11,16}$"

AMEXCardFormatRegex = regexp.MustCompile(amexCardFormatString)
VISACardFormatRegex = regexp.MustCompile(visaCardFormatString)
Expand Down
153 changes: 80 additions & 73 deletions payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,86 @@ package dough
import "testing"

var testCards = map[string]string{
"4111111111111111": "visa",
"4457010000000009": "visa",
"4457010100000008": "visa",
"4457010140000141": "visa",
"4457010200000247": "visa",
"4100200300011001": "visa",
"4100200300012009": "visa",
"4100200300013007": "visa",
"4100200310000002": "visa",
"4024720001231239": "visa",
"4457012400000001": "visa",
"4457013200000001": "visa",
"4457119922390123": "visa",
"4457000300000007": "visa",
"4457000100000009": "visa",
"4457003100000003": "visa",
"4457000400000006": "visa",
"4457000200000008": "visa",
"4457000800000002": "visa",
"4457000900000001": "visa",
"4457001000000008": "visa",
"4005550000081019": "visa",
"4000000000000002": "visa",
"2223000148400010": "mastercard",
"2223000048400011": "mastercard",
"2223280062080010": "mastercard",
"2222630061560019": "mastercard",
"2222470061880012": "mastercard",
"2222400061240016": "mastercard",
"2222400041240011": "mastercard",
"2223520063560019": "mastercard",
"2223520043560014": "mastercard",
"2222420040560011": "mastercard",
"2222410040360017": "mastercard",
"2223020040760014": "mastercard",
"5112000100000003": "mastercard",
"5112002100000009": "mastercard",
"5112002200000008": "mastercard",
"5112000200000002": "mastercard",
"5112000300000001": "mastercard",
"5112000400000000": "mastercard",
"5112010400000009": "mastercard",
"5112000600000008": "mastercard",
"5112010000000003": "mastercard",
"5112010100000002": "mastercard",
"5112010140000004": "mastercard",
"5154605300000121": "mastercard",
"5167001020236549": "mastercard",
"5500000254444445": "mastercard",
"5592106621450897": "mastercard",
"5590409551104142": "mastercard",
"5587755665222179": "mastercard",
"5445840176552850": "mastercard",
"5390016478904678": "mastercard",
"5112010201000109": "mastercard",
"5112010202000108": "mastercard",
"5194560012341234": "mastercard",
"5435101234510196": "mastercard",
"5407102010000018": "mastercard",
"5112000900000005": "mastercard",
"6011010000000003": "discover",
"6011010100000002": "discover",
"6011010140000004": "discover",
"375000026600004": "amex",
"375001000000005": "amex",
"375001010000003": "amex",
"375001014000009": "amex",
"341234567890127": "amex",
"378734493671000": "amex",
"3530111333300000": "jcb",
"3566002020360505": "jcb",
"30569309025904": "diners",
"38520000023237": "diners",
"4111111111111111": "visa",
"4457010000000009": "visa",
"4457010100000008": "visa",
"4457010140000141": "visa",
"4457010200000247": "visa",
"4100200300011001": "visa",
"4100200300012009": "visa",
"4100200300013007": "visa",
"4100200310000002": "visa",
"4024720001231239": "visa",
"4457012400000001": "visa",
"4457013200000001": "visa",
"4457119922390123": "visa",
"4457000300000007": "visa",
"4457000100000009": "visa",
"4457003100000003": "visa",
"4457000400000006": "visa",
"4457000200000008": "visa",
"4457000800000002": "visa",
"4457000900000001": "visa",
"4457001000000008": "visa",
"4005550000081019": "visa",
"4000000000000002": "visa",
"2223000148400010": "mastercard",
"2223000048400011": "mastercard",
"2223280062080010": "mastercard",
"2222630061560019": "mastercard",
"2222470061880012": "mastercard",
"2222400061240016": "mastercard",
"2222400041240011": "mastercard",
"2223520063560019": "mastercard",
"2223520043560014": "mastercard",
"2222420040560011": "mastercard",
"2222410040360017": "mastercard",
"2223020040760014": "mastercard",
"5112000100000003": "mastercard",
"5112002100000009": "mastercard",
"5112002200000008": "mastercard",
"5112000200000002": "mastercard",
"5112000300000001": "mastercard",
"5112000400000000": "mastercard",
"5112010400000009": "mastercard",
"5112000600000008": "mastercard",
"5112010000000003": "mastercard",
"5112010100000002": "mastercard",
"5112010140000004": "mastercard",
"5154605300000121": "mastercard",
"5167001020236549": "mastercard",
"5500000254444445": "mastercard",
"5592106621450897": "mastercard",
"5590409551104142": "mastercard",
"5587755665222179": "mastercard",
"5445840176552850": "mastercard",
"5390016478904678": "mastercard",
"5112010201000109": "mastercard",
"5112010202000108": "mastercard",
"5194560012341234": "mastercard",
"5435101234510196": "mastercard",
"5407102010000018": "mastercard",
"5112000900000005": "mastercard",
"6011010000000003": "discover",
"6011010100000002": "discover",
"6011010140000004": "discover",
"6011010000000003011": "discover",
"6011010100000002011": "discover",
"6011010140000000011": "discover",
"375000026600004": "amex",
"375001000000005": "amex",
"375001010000003": "amex",
"375001014000009": "amex",
"341234567890127": "amex",
"378734493671000": "amex",
"3530111333300000": "jcb",
"3566002020360505": "jcb",
"3530111333300000332": "jcb",
"3566002020360505005": "jcb",
"30569309025904": "diners",
"38520000023237": "diners",
"3056930902590411014": "diners",
"3852000002323711017": "diners",
}

func TestValidLuhn(t *testing.T) {
Expand Down

0 comments on commit 48c8420

Please sign in to comment.