### WEBINAR:On-Demand

Virtual Developer Workshop: Containerized Development with Docker

' ' Usage: Returns Boolean indicating whether or not credit card ' number given passes the Luhn Formula (as described in ' ISO/IEC 7812-1:1993). Only numbers and numerical strings ' accepted, remove any spaces and dashes in strings. ' Example: ' booAcceptCard = CheckCC("4000000000000002") ' Function CheckCC(CCNo) Dim I, w, x, y ' y = 0 CCNo = CStr(CCNo) ' 'Process digits from right to left, drop last digit if total 'length is even ' w = 2 * (len(CCNo) Mod 2) ' for I = len(CCNo) - 1 to 1 step -1 x = mid(CCNo, I, 1) ' If IsNumeric(x) then Select Case (I Mod 2) + w Case 0, 3 ' 'Even Digit - Odd where total length is odd '(eg. Visa vs. Amx) ' y = y + CInt(x) Case 1, 2 ' 'Odd Digit - Even where total length is odd ' (eg. Visa vs. Amx) ' x = CInt(x) * 2 If x > 9 then ' 'Break the digits (eg. 19 becomes 1 + 9) ' y = y + (x \ 10) + (x - 10) else y = y + x End If End Select End If next ' 'Return the 10's complement of the total y = 10 - (y Mod 10) ' If y > 9 then y = 0 CheckCC = (CStr(y) = Right\$(CCNo, 1)) End Function

• #### cards

Posted by Legacy on 12/08/2003 08:00am

Originally posted by: gabreal

```how to check remaining amount in a creditcard
```

• #### fnLuhnCheck

Posted by Legacy on 10/22/2003 07:00am

Originally posted by: Aijaz Ahmed

I am chaking the Luhn of credit card The code is given below
plz suggest me where i am making mistake and what?

Private Function fnLuhnCheck(strCCNumber As String, strCCType As String) As Boolean
Dim strRev As String
Dim strCh As String
Dim intNumber As Integer
Dim strNumberFinal As Integer
Dim intsum As Integer
Dim validLuhn As Boolean
strRev = StrReverse(strCCNumber)
For intTemp = 1 To Len(strRev)
strCh = Mid(strRev, intTemp, 1)
intNumber = CInt(strCh)
If intTemp Mod 2 = 0 Then
intNumber = intNumber * 2
If intNumber > 9 Then
intNumber = intNumber - 9
End If
End If
strNumberFinal = strNumberFinal & intNumber
Next intTemp
For intTemp = 1 To Len(strNumberFinal)
intsum = intsum + Mid(strNumberFinal, intTemp, 1)
Next intTemp
If intsum Mod 10 = 0 Then
validLuhn = True
Else
validLuhn = False
End If
fnLuhnCheck = validLuhn

End Function

• #### fnLuhnCheck

Posted by Legacy on 10/22/2003 07:00am

Originally posted by: Aijaz Ahmed

I am chaking the Luhn of credit card The code is given below
plz suggest me where i am making mistake and what?

Private Function fnLuhnCheck(strCCNumber As String, strCCType As String) As Boolean
Dim strRev As String
Dim strCh As String
Dim intNumber As Integer
Dim strNumberFinal As Integer
Dim intsum As Integer
Dim validLuhn As Boolean
strRev = StrReverse(strCCNumber)
For intTemp = 1 To Len(strRev)
strCh = Mid(strRev, intTemp, 1)
intNumber = CInt(strCh)
If intTemp Mod 2 = 0 Then
intNumber = intNumber * 2
If intNumber > 9 Then
intNumber = intNumber - 9
End If
End If
strNumberFinal = strNumberFinal & intNumber
Next intTemp
For intTemp = 1 To Len(strNumberFinal)
intsum = intsum + Mid(strNumberFinal, intTemp, 1)
Next intTemp
If intsum Mod 10 = 0 Then
validLuhn = True
Else
validLuhn = False
End If
fnLuhnCheck = validLuhn

End Function

• #### Formation criteria of a sequence of numbers!! Help me!!

Posted by Legacy on 08/30/2003 07:00am

Originally posted by: Tiago

```Does anybody know how may I check the formation criteria of a sequence of numbers??!?! For example, I have 5 different sequences of numbers and the 5 sequences have the same formation criteria. Like the credit card numbers, for example... thanks!
```

• #### What if the Credit Card is expired?

Posted by Legacy on 02/24/2003 08:00am

Originally posted by: Bryan

So how can you check if the Card has already expired?

• #### another way...

Posted by Legacy on 03/27/2001 08:00am

Originally posted by: Ben

```Using the simpler way
(http://beaver.dburry.com/tutorial/ccvalidate.html) as a base I wrote this quick function in VB which does the same thing as the one in this artical:

Function mod10 ( num As String ) As Boolean
On Error GoTo mod10_err
Dim sum As Integer
Dim i As Integer

num = trim(num)
If Len(num) Mod 2 > 0 Then num = "0" + num
For i = Len(num) To 1 Step -2
sum = sum +  Cint(Mid\$(num, i, 1)) + (Cint(Mid\$(num, i - 1, 1)) * 2)
If (Cint(Mid\$(num, i - 1, 1)) >= 5) Then sum = sum - 9
Next
mod10 = (( sum Mod 10 ) = 0 )

Exit Function
mod10_err:
' we probably got here because the 'number' contained non-numeric characters
mod10 = FALSE
End Function
```

• #### simpler way to do this

Posted by Legacy on 12/27/2000 08:00am

Originally posted by: Dave

Sorry it's not in the same language but there is a simpler way to do this illustrated at http://beaver.dburry.com/tutorial/ccvalidate.html

Dave

• #### Check Credit Card Number

Posted by Legacy on 11/13/2000 08:00am

Originally posted by: Michael

Very good depiction of the luhn formula

good work

• You must have javascript enabled in order to post comments.