Sunday, 22 May 2022

Chapter 23 // Exercise 7 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 23 // Exercise 7

Write a program (similar to the one in the previous exercise) that finds credit card numbers in a file. Do a bit of research to find out what credit card formats are really used.


So I thought credit card numbers were straight forward; literally just 16 digits separated by a space (at least that's what it is on my credit card). I never realised they were all different, I've only ever had a mastercard.

I found this site:
and decided to write patterns for the 3 most common; visa, mastercard and amex. This site was also incredibly useful:

I got a load of test credit card numbers from this site and added some more to it:

Whilst doing this I saw more posts about how regex should not be used for data validation. I even found sites like paypal providing test credit card numbers and they had all spaces stripped out.

I did check for any whitespace separating characters after the max length of the number though because, well they should be separated in a text file anyway.

No comments:

Post a Comment