LUHN Credit card number validation

Jean-Pierre A. Radley appl at jpr.com
Mon Jul 18 10:22:26 PDT 2005


Wally Turnbull propounded (on Sun, Jul 17, 2005 at 10:34:25PM -0400):
| Does anyone have a filePro LUHN credit card number validation routine to
| share that will check to see if 13, 14, 15, and 16 digit credit card
| numbers have a valid checksum?  I'm looking for filePro code - not the
| formula.  I would like not to reinvent this tedious wheel if it is not
| necessary.

I've attached fP code that Peter Klaasen posted here last December.


-- 
JP
-------------- next part --------------
:'Luhn Check Control for 16 digit creditcards:'Peter Klaassen - NCC - Holland - Sep.9-1999:
::declare extern creditcardnumber:
::declare global firstfifteen (15,.0):
::declare global checkdigit(1,.0):
::declare global counter(2,.0):
::declare global additionresult(3,.0):
::declare global substractionresult(3,.0):
:'fill real part of creditcardnumber:firstfifteen=mid(creditcardnumber,"1","15"):
:'fill checkdigit of creditcardnumber:checkdigit=mid(creditcardnumber,"16","1"):
::dim result (15)(1,.0):
::counter="1":
uneven:'multiply 1,3,5,7,9,11,13,15 position by 2::
:counter gt "15":counter="2";goto even:
::result(counter)=(mid(firstfifteen,counter,"1")*"2"):
:mid(firstfifteen,counter,"1") eq "5":result(counter)="1":
:mid(firstfifteen,counter,"1") eq "6":result(counter)="3":
:mid(firstfifteen,counter,"1") eq "7":result(counter)="5":
:mid(firstfifteen,counter,"1") eq "8":result(counter)="7":
:mid(firstfifteen,counter,"1") eq "9":result(counter)="9":
::counter=counter+"2";goto uneven:
even:'multiply 2,4,6,8,10,12,14 position by 1::
:counter gt "14":counter="1";goto count:
::result(counter)=mid(firstfifteen,counter,"1"):
::counter=counter+"2";goto even:
count:'add all results::
:counter gt "15":goto check:
::additionresult=additionresult+result(counter):
::counter=counter+"1";goto count:
check::'maximum of multiplying is 200:
:'deduct addition total from 200:substractionresult="200"-additionresult:
:mid(substractionresult,"3","1") eq checkdigit:end                        'check digit is ok:
:'English reply:'errorbox "Creditcardnumber is not OK":
:'Dutch reply:errorbox "Creditcardnummer is niet OK","Kies \KZ":
:'jumps back into the field:screen ,(@fd):
::end:


More information about the Filepro-list mailing list