Validating Credit Card Numbers

The following function validates credit card numbers.

The following function validates credit card numbers. 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. If the function validates a card, it doesn't mean the card is actually good, it means only that the numbers are arranged in a valid format. If a card isn't validated, you've saved some card-processing time. 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 August 2001
This Content Component encountered an error

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:

-ADS BY GOOGLE

SearchWindowsServer

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

SearchDataCenter

SearchExchange

SearchContentManagement

Close