1
votes

I'm trying to set the credit card numbers based on the standard check parameters but I am finding lots of UK cards (Maestro / Visa Debit / Barclaycard Connect) have start numbers that don't meet other card validation script regexes;

I.e Maestro (Switch) cards are still around and start with a 4, using a lot of the regexes online this would cause Visa Credit card to be selected.

Does anyone know of a resource where these registered start codes are stored?

Ta

Anyone Looking for a UK Credit Card Validation Table (BIN TABLE)

http://www.barclaycard.co.uk/business/documents/pdfs/bin_rules.pdf

4
Well done on that BIN table. Exactly what I've been looking for. - Martin Clarke
Thanks, Its a nightmare finding useful information to validate against :o) - Chris McKee

4 Answers

1
votes

Here are the rules regarding credit card formatting and validation.

Note: Switch cards are actually debit not credit cards so have different validation rules. In fact Switch cards normally have the account number embedded in the number. There's probably a checksum algorithm for this but I haven't seen it (yet).

1
votes

You cannot rely on a regex to validate card numbers. You need a recent card validation table that includes lengths for ranges and range to type mappings. Your payment gateway provider should be able to provide you with an up to date validation table.

You can often rely on Luhn for an is-this-number-made-up type of validation but in order to pass your gateway's liability tests, you need to validate that the user has entered the write card type for the number and if a start date is required by the provider, it must be entered, etc...

Here's a Luhn example in C#:

public static bool IsLuhnValid(string cardNumber) {
    if (string.IsNullOrEmpty(cardNumber))
        return false;
    Int64 cardNumberAsBigInt;
    if (!Int64.TryParse(cardNumber, out cardNumberAsBigInt) || (cardNumberAsBigInt == 0))
        return false;
    int indicator = 1;
    int firstNumberToAdd = 0;
    int secondNumberToAdd = 0;
    for (int i = cardNumber.Length - 1; i >= 0; i--) {
        int currentNumber = int.Parse(cardNumber[i].ToString());
        if (indicator == 1) {
            firstNumberToAdd += currentNumber;
            indicator = 0;
        }
        else {
            int doubleCurrentNumber = currentNumber + currentNumber;
            if (doubleCurrentNumber >= 10) {
                int num1 = Convert.ToInt32(doubleCurrentNumber.ToString().Substring(0, 1));
                int num2 = Convert.ToInt32(doubleCurrentNumber.ToString().Substring(1, 1));
                secondNumberToAdd += num1 + num2;
            }
            else {
                secondNumberToAdd += doubleCurrentNumber;
            }
            indicator = 1;
        }
    }
    return ((firstNumberToAdd + secondNumberToAdd) % 10 == 0);
}
0
votes

i dont knwo about registered start codes, but I got a script that works fine for cc validation (its javascript): Determine credit card type by number?

this is heavily tested and is used with quite a lot of transactions so it should take care of all special cases (if you change it into a regexp could you share it ?)

0
votes

BIN (Bank Identification Number) resources on Wiki