I have a large text file containing credit card numbers, I've been told I need to look through this file and then find possible credit card numbers, I've been using Notepad ++ 'Find in Files' regular expression search mode using this simple expression: 4\d{15} (this searches for a 16 digit long string starting with 4 which is usually a VISA Debit/Credit) and then I copy and paste it into a Credit Card Validation script.
Is there anyway to create an expression that will search for 16 digit long strings starting with 4, and checks to see if it uses the Luhn Algorithm (makes sure it is valid).
This is the Luhn Algorithm:
1) Starting with the second to last digit and moving left, double the value of all the alternating digits.
2) Starting from the left, take all the unaffected digits and add them to the results of all the individual digits from step 1. If the results from any of the numbers from step 1 are double digits, make sure to add the two numbers first (i.e. 18 would yield 1+8). Basically, your equation will look like a regular addition problem that adds every single digit.
3) The total from step 2 must end in zero for the credit-card number to be valid.
Here's a simple LINQPad program that extracts all 16-digit numbers that starts with a 4 from the file: