1

We've all seen (and probably used) one of the many regex patterns for validating various credit cards...

Are there any "OFFICIAL" regex patterns published by the card companies themselves?

Are these patterns all simply submitted by the community?

Cœur
  • 37,241
  • 25
  • 195
  • 267
kevcoder
  • 883
  • 1
  • 15
  • 29

1 Answers1

1

There is no regex pattern that can perfectly validate a card number. The various solutions that are out there are very basic checks that cover the first few digits only. In reality there are often huge gaps within those ranges where cards have not yet been assigned by any card issuer.

You can sanity check the first few digits, card length and luhn check digit, but the only way to completely validate a card is to submit it to the processor for validation and authorization.

PaulG
  • 13,871
  • 9
  • 56
  • 78
  • +1 to @PaulG for his answer, however what's missing there is the "why". A credit card company will never publish any "formal" regex, for security purposes. It is in their best interest (and, as their customer, your interest too) that the you can only validate a credit card number by invoking their service; that way, they can monitor fraudulent validation patterns. – Isaac Nov 22 '12 at 06:20