VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Validates a credit card number using the Luhn Modulo 10+5 algorithm. Doesn't tell you if it's a liv

by Andy Henderson (4 Submissions)
Category: Encryption
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 22nd April 2009
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Validates a credit card number using the Luhn Modulo 10+5 algorithm. Doesn't tell you if it's a live credit cardnumber just that it would be

Rate Validates a credit card number using the Luhn Modulo 10+5 algorithm. Doesn't tell you if it's a liv



Function LuhnVerify(ByVal CC As String) As Boolean
    
    Dim s As String
    Dim ctr As Integer
    
    'force the number to atleast one digit
    CC = "0" & Trim(CC)
    
    ' force card number to even length
    If Len(CC) <> (Len(CC) / 2) Then
        CC = "0" & CC
    End If

    For n = (Len(CC) - 1) To 1 Step -2
        s = s & (2 * Val(Mid(CC, n, 1)))
    Next
    
    For n = (Len(CC)) To 1 Step -2
        s = s & Mid(CC, n, 1)
    Next
    
    For n = 1 To Len(s)
        ctr = ctr + Val(Mid(s, n, 1))
    Next
    
    ctr = ctr Mod 10
    
    If ctr = 0 Or ctr = 5 Then  ' supports Mod 10+5 Variant
        LuhnVerify = True
    Else
        LuhnVerify = False
    End If
    
End Function


Download this snippet    Add to My Saved Code

Validates a credit card number using the Luhn Modulo 10+5 algorithm. Doesn't tell you if it's a liv Comments

No comments have been posted about Validates a credit card number using the Luhn Modulo 10+5 algorithm. Doesn't tell you if it's a liv. Why not be the first to post a comment about Validates a credit card number using the Luhn Modulo 10+5 algorithm. Doesn't tell you if it's a liv.

Post your comment

Subject:
Message:
0/1000 characters