Hi,
I found this code on the net when looking for a way for one of our departments to verify whether a credit card number given over the phone is a real CC number.
This is to save them having to ring customers back when incorrect data has been given....and yes, they do read the numbers back to customers
function checkcc(ccnumber,cctype)
'checks credit card number for checksum,length and type
'ccnumber= credit card number (all useless characters are
' being removed before check, we hope)
'
'cctype:
' "V" VISA
' "M" Mastercard/Eurocard
' "A" American Express
' "C" Diners Club / Carte Blanche
' "D" Discover
' "E" enRoute
' "J" JCB
' this routine doe NOT handle 'SWITCH' (UK+) credit cards
'returns: checkcc=0 (Bit0) : card valid
' checkcc=1 (Bit1) : wrong type
' checkcc=2 (Bit2) : wrong length
' checkcc=4 (Bit3) : wrong checksum (MOD10-Test)
' checkcc=8 (Bit4) : cardtype unknown
'
ctype=ucase(cctype)
select case ctype
case "V"
cclength="13;16"
ccprefix="4"
case "M"
cclength="16"
ccprefix="51;52;53;54;55"
case "A"
cclength="15"
ccprefix="34;37"
case "C"
cclength="14"
ccprefix="300;301;302;303;304;305;36;38"
case "D"
cclength="16"
ccprefix="6011"
case "E"
cclength="15"
ccprefix="2014;2149"
case "J"
cclength="15;16"
ccprefix="3;2131;1800"
case else
cclength="13;14;15;16"
ccprefix="1;2;3;4;5;6"
end select
prefixes=split(ccprefix,";",-1)
lengths=split(cclength,";",-1)
number=trimtodigits(ccnumber)
prefixvalid=false
lengthvalid=false
for each prefix in prefixes
if instr(number,prefix)=1 then
prefixvalid=true
end if
next
for each length in lengths
if cstr(len(number))=length then
lengthvalid=true
end if
next
result=0
if not prefixvalid then
result=result+1
end if
if not lengthvalid then
result=result+2
end if
qsum=0
for x=1 to len(number)
ch=mid(number,len(number)-x+1,1)
'response.write ch
if x mod 2=0 then
sum=2*cint(ch)
qsum=qsum+(sum mod 10)
if sum>9 then
qsum=qsum+1
end if
else
qsum=qsum+cint(ch)
end if
next
'response.write qsum
if qsum mod 10<>0 then
result=result+4
end if
if cclength="" then
result=result+8
end if
checkcc=result
end function
CODE ENDS:
The problem I have is firstly the SPLIT function. Is there an equivalent Access function?
If you would prefer to see the code in it's original context. Please go here...
I would appreciate anyone pointing me in the right direction with this one.
Regards,
Peter
PS. Sorry the code is so long.
Remember- It's nice to be important,
but it's important to be nice
I found this code on the net when looking for a way for one of our departments to verify whether a credit card number given over the phone is a real CC number.
This is to save them having to ring customers back when incorrect data has been given....and yes, they do read the numbers back to customers
function checkcc(ccnumber,cctype)
'checks credit card number for checksum,length and type
'ccnumber= credit card number (all useless characters are
' being removed before check, we hope)
'
'cctype:
' "V" VISA
' "M" Mastercard/Eurocard
' "A" American Express
' "C" Diners Club / Carte Blanche
' "D" Discover
' "E" enRoute
' "J" JCB
' this routine doe NOT handle 'SWITCH' (UK+) credit cards
'returns: checkcc=0 (Bit0) : card valid
' checkcc=1 (Bit1) : wrong type
' checkcc=2 (Bit2) : wrong length
' checkcc=4 (Bit3) : wrong checksum (MOD10-Test)
' checkcc=8 (Bit4) : cardtype unknown
'
ctype=ucase(cctype)
select case ctype
case "V"
cclength="13;16"
ccprefix="4"
case "M"
cclength="16"
ccprefix="51;52;53;54;55"
case "A"
cclength="15"
ccprefix="34;37"
case "C"
cclength="14"
ccprefix="300;301;302;303;304;305;36;38"
case "D"
cclength="16"
ccprefix="6011"
case "E"
cclength="15"
ccprefix="2014;2149"
case "J"
cclength="15;16"
ccprefix="3;2131;1800"
case else
cclength="13;14;15;16"
ccprefix="1;2;3;4;5;6"
end select
prefixes=split(ccprefix,";",-1)
lengths=split(cclength,";",-1)
number=trimtodigits(ccnumber)
prefixvalid=false
lengthvalid=false
for each prefix in prefixes
if instr(number,prefix)=1 then
prefixvalid=true
end if
next
for each length in lengths
if cstr(len(number))=length then
lengthvalid=true
end if
next
result=0
if not prefixvalid then
result=result+1
end if
if not lengthvalid then
result=result+2
end if
qsum=0
for x=1 to len(number)
ch=mid(number,len(number)-x+1,1)
'response.write ch
if x mod 2=0 then
sum=2*cint(ch)
qsum=qsum+(sum mod 10)
if sum>9 then
qsum=qsum+1
end if
else
qsum=qsum+cint(ch)
end if
next
'response.write qsum
if qsum mod 10<>0 then
result=result+4
end if
if cclength="" then
result=result+8
end if
checkcc=result
end function
CODE ENDS:
The problem I have is firstly the SPLIT function. Is there an equivalent Access function?
If you would prefer to see the code in it's original context. Please go here...
I would appreciate anyone pointing me in the right direction with this one.
Regards,
Peter
PS. Sorry the code is so long.
Remember- It's nice to be important,
but it's important to be nice