Regex Guru

Thursday, 13 March 2008

Validating Credit Card Numbers

Filed under: Regex Examples — Jan Goyvaerts @ 8:33

After you’ve graciously stripped out spaces and dashes, you can check whether the card number looks like a valid number and even determine the brand of the card with a few simple regular expressions. I’ve published a new article on finding and verifying credit card numbers on regular-expressions.info with some in-depth information and a full set of example regexes.

2 Comments

  1. Do these credit card numbers also contain a checksum number at the end? I know my belgian banck card nr does. If this is the case than, as for as my regex knowledge goes, it can’t be checked by a regex.

    Comment by Tom Pester — Sunday, 30 March 2008 @ 15:24

  2. The checksum number is calculated with the Luhn algorithm that I mentioned in my article.

    You indeed can’t check that with a regex.

    Comment by Jan — Monday, 31 March 2008 @ 8:26

Sorry, the comment form is closed at this time.