Pre-validating credit card numbers

Here's a quick way to cut down on credit card processing time. The following function checks the validity of credit card numbers. If the number is in valid format, that does not mean that the credit card is valid, only that the number combination is valid. This can save you a lot of valuable credit card processing time. If the number is in a valid format, the function returns "True"; if the number is in an invalid format, it returns "False". This algorithm should work with all credit cards. You can easily use this function in Common Gateway Interface (CGI) forms that process credit card orders.
Function CheckCard(CCNumber As String) As Boolean
Dim Counter As Integer, TmpInt As Integer
Dim Answer As Integer

Counter = 1
TmpInt = 0

While Counter < = Len(CCNumber)
If IsEven(Len(CCNumber)) Then
TmpInt = Val(Mid$(CCNumber, Counter, 1))
If Not IsEven(Counter) Then
TmpInt = TmpInt * 2
If TmpInt > 9 Then TmpInt = TmpInt - 9
End If
Answer = Answer + TmpInt
'Debug.Print Counter, TmpInt, Answer
Counter = Counter + 1
Else
TmpInt = Val(Mid$(CCNumber, Counter, 1))
If IsEven(Counter) Then
TmpInt = TmpInt * 2
If TmpInt > 9 Then TmpInt = TmpInt - 9
End If
Answer = Answer + TmpInt
'Debug.Print Counter, TmpInt, Answer
Counter = Counter + 1
End If
Wend

Answer = Answer Mod 10

If Answer = 0 Then CheckCard = True
End Function
This was first published in March 2001

Dig deeper on Domino Resources

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close