views:

507

answers:

4

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

I.e Maestro (Switch) cards are still around and start with a 4, using alot of the regex's 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.barclaycardbusiness.co.uk/information%5Fzone/processing/bin%5Frules.html Link to the latest is on here

A: 

i dont knwo about registered start codes, but I got a script that works fine for cc validation (its javascript): http://stackoverflow.com/questions/1308194/determine-credit-card-type-by-number/1308240#1308240

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 ?)

Niko
+1  A: 

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).

cletus
Yep all Maestro cards are debit; and from the 7th digit in it contains the account code. Might have to get a data validation table.
Chris M
A: 

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);
}
grenade
Its as a precursory selection; like google checkout, you enter your number and it pre-selects the card type.
Chris M
Ta we do have a LUHN method built in to our validation class; as were using a webservice that currently only accepts a single call per session (dont ask) we have to do as much validation as is humanly possible prior to sending the information.
Chris M
A: 

BIN (Bank Identification Number) resources on WIKI

Hope that helps,

Dan

Daniel Elliott
Ta, unfortunatly the data on there is mostly out of date; Visa Electron is Visa Debit and the start numbers no longer match. Obviously with the debit card inclusive you cant simply match against the 4 (which sucks) :op
Chris M