Make your own free website on Tripod.com

Check If Credit Card Number Is Valid

'This program will return True if the credit card number is valid, and False if it's not valid.
'This program good for all kinds of credit cards.
'Insert the following code to your form:

Function isEven(n As Integer) As Boolean
isEven = True
If n And 1 Then isEven = False
End Function

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
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
Counter = Counter + 1
End If
Wend
Answer = Answer Mod 10
If Answer = 0 Then CheckCard = True
End Function

Private Sub Form_Load()
'Replace '1234567890123456' with the credit card number you want to validate.
MsgBox CheckCard("1234567890123456")
End Sub

Go Back