|
If it's credit card check digit processing you want, here's what we use:
*//////////////////////////////////////////////////////////////*
* (CheckCC) Validate Credit Card Number *
*//////////////////////////////////////////////////////////////*
PCheckCC B
*--------------------------------------------------------------*
DCheckCC PI 1A
D CCnumber 25A value
D CCType 2A value
DWorkCCnum S 25A
DPos S 2S 0
DLen S 2S 0
DValidCC S 1A
DValidPrefix S 1A
DValidLength S 1A
DCCLength S 2S 0 dim(2)
DCCPrefix S 4A dim(8)
DPrefixCtr S 2S 0
DPrefixLen S 2S 0
DTestDigDS DS
D TestDigit 1 1A
D TestDigitN 1 1S 0
C eval ValidCC='N'
C movea *zeros CCLength
C movea *blanks CCPrefix
* Determine card type. If this is a PO, don't validate it.
C If CCType='po'
C eval ValidCC='Y'
C eval ValidPrefix='N'
C eval ValidLength='N'
C Else
C Select
C When CCType='vs'
C eval CCLength(1)=13
C eval CCLength(2)=16
C eval CCPrefix(1)='4'
C eval PrefixCtr=1
C When CCType='mc'
C eval CCLength(1)=16
C eval CCPrefix(1)='51'
C eval CCPrefix(2)='52'
C eval CCPrefix(3)='53'
C eval CCPrefix(4)='54'
C eval CCPrefix(5)='55'
C eval PrefixCtr=5
C When CCType='am'
C eval CCLength(1)=15
C eval CCPrefix(1)='34'
C eval CCPrefix(2)='37'
C eval PrefixCtr=2
C When CCType='dc'
C eval CCLength(1)=16
C eval CCPrefix(1)='6011'
C eval PrefixCtr=1
C EndSl
* Strip out non-numbers
C eval Pos=0
C eval WorkCCNum=''
C DoW Pos < %len(%trim(CCNumber))
C eval Pos=Pos+1
C eval TestDigit=%subst(CCNumber:Pos:1)
C If (TestDigit>='0') AND (TestDigit<='9')
C eval WorkCCNum=%trim(WorkCCNum)+TestDigit
C EndIf
C EndDo
* Verify number lengths
C If (%len(%trim(WorkCCNum))=CCLength(1)) OR
C (%len(%trim(WorkCCNum))=CCLength(2))
C eval ValidPrefix='Y'
C EndIf
* Verify card prefixes
C eval Pos=0
C DoW Pos < PrefixCtr
C eval Pos=Pos+1
C eval PrefixLen=%len(%trim(CCPrefix(Pos)))
C If %subst(WorkCCNum:1:PrefixLen)=
C %trim(CCPrefix(Pos))
C eval ValidLength='Y'
C EndIf
C EndDo
* Verify check digit
C eval Pos=0
C eval Len=%len(%trim(WorkCCNum))
C z-add *zeros sum 10 0
C z-add *zeros qsum 10 0
C DoW Pos < Len
C eval Pos=Pos+1
C eval TestDigit=%subst(WorkCCNum:Len-Pos+1:1)
C If #mod(Pos:2) = 0
C eval sum=2 * TestDigitN
C eval qsum=qsum + #mod(sum:10)
C If sum>9
C eval qsum=qsum+1
C EndIf
C Else
C eval qsum=qsum+TestDigitN
C EndIf
C EndDo
C If (#mod(qsum:10) = 0)
C AND (ValidLength = 'Y')
C AND (ValidPrefix='Y')
C eval ValidCC='Y'
C EndIf
C EndIf
C return ValidCC
PCheckCC E
I basically ported over an ASP example of this several years ago and we haven't
had any problems with it. The type is the card type (vs=Visa, mc=MasterCard,
am=American Express, dc=Discover) except for type=po, we use that to say
Purchase Order which obviously doesn't need to go through this routine. The
example I found had a few other card types defined but I don't have the URL to
it anymore. A search on Google should turn up plenty of examples for the major
cards.
Matt
-----Original Message-----
From: Bob Cozzi [mailto:cozzi@xxxxxxxxx]
Sent: Wednesday, February 25, 2004 10:34 AM
To: 'RPG programming on the AS400 / iSeries'
Subject: RE: Modulus 10 formula (REPOST)
Crap! That's what I thought. :(
-Bob
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Barr, Regan
Sent: Wednesday, February 25, 2004 9:26 AM
To: RPG400-L
Subject: RE: Modulus 10 formula (REPOST)
Bob,
I'm just finishing up a credit card project, and I found that there seem to
be as many versions of the
Mod10 as there are merchants/card issuers. I was working primarily with
validating merchant numbers.
<snip>
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.