[Gllug] (OT) Resources for information on UK credit and debit cards

Mike Leigh mikel at hornbill.com
Fri Nov 26 13:50:31 UTC 2004


In case you want Switch / Maestro / Solo
Card Type		Prefix	Length
Solo			67		16
Switch / Meastro	67		18

hth

Mike

-----Original Message-----
From: Liam Delahunty [mailto:liamvictor at gmail.com]
Sent: 26 November 2004 13:24
To: Greater London Linux Users Group
Subject: Re: [Gllug] (OT) Resources for information on UK credit and
debit cards


On Fri, 26 Nov 2004 12:55:54 +0000, Simon Perry wrote:
> I want to implement a credit card validation routine on the order page
> of a website I'm working on that will weed out invalid cards before I do
> the actual call to secpay to handle the transaction. What I need to know
> is the prefix for switch, delta, solo, maestro cards, the valid lengths

All credit/debit cards do the luhn 10 test. I've got a basic list of
cards _somewhere_ but all can find of the moment is:

/*
Card Type 					Prefix
Length 
MasterCard 					51-55
16 
VISA 						4
13, 16 
American Express (AMEX) 	34, 37 				15 
Diners Club/Carte Blanche 	300-305, 36, 38 	14 
enRoute 					2014, 2149
15 
Discover 					6011
16 
JCB 						3
16 
JCB 						2131, 1800
15 
*/

Apologies if gmail screws the tabbing - in visa they have two lengths,
all the others just one.

Now this is pretty old and obviously crap, but it's a start...
Personally I've just requested the user selects a card type, and I
only do the very basic validation of seeing if it's more-or-less what
they claim it is. When the card is processed the actual issuer is of
little importance (using a HSBC PDQ, might be different with secpay)
however I'd still be interested in other prefix/codes just to imporve
the routine.

The luhn 10 I do is:
$cc_num_test = eregi_replace("[^0-9]","", $cc_num);
$cc_num_len = strlen($cc_num_test);
// if uneven add a zeo at begining
if (($cc_num_len % 2) != 0){
	$cc_num_test = "0" . $cc_num_test;
	$cc_num_len++;
}

for ($p=0; $p<$cc_num_len; $p++){
	if ($p %2 == 0){
		$here = substr($cc_num_test, $p, 1);
		if ($here*2 > 9){
			$here = ($here*2)-9;
		}else{
			$here = $here*2;
		}
		$x = $x + $here;
	}else{
		$here = substr($cc_num_test, $p, 1);
		$y = $y + $here;
	}
}
$tot = $x + $y;
if ($tot % 10 != 0){
	$err_array[cc_num] = "<b>Error</b> Your credit card number $cc_num
doesn't appear to be valid.";
}
}

wrote it YEARS ago and the code is not great, but it does the job.

-- 
Kind regards, Liam Delahunty
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list