Luhn

Luhn function to return true or false if is valid based on Luhn identification number requirements (Modulus 10 or Mod10)
Identification numbers like Credit card, Social Insurance, IMEI, etc.
More on https://www.geeksforgeeks.org/luhn-algorithm/

CodeFunctionName
What is this?

Public

Tested

Imported
Function Luhn(s)
    ' Luhns("79927398713") = True
    ' Luhns("") = False
    Dim i, iOdd, iEven, sInv, iNum
    i = 1
    iOdd = 0
    iEven = 0
    sInv = StrReverse(s)
    Do While (i <=Len(sInv))
        If Odd(i) Then
            iOdd = iOdd + CByte(Mid(sInv, i, 1))
        Else
            iNum = 2 * CByte(Mid(sInv, i, 1))
            If (iNum > 9) then
                iEven = iEven + 1 + (iNum - 10)
            Else
                iEven = iEven + iNum
            End If
        End If
        i = i + 1
    Loop
    Luhn = (i >1) and ((iOdd + iEven) mod 10 = 0)
End Function

s

Luhns("79927398713") = True
Luhns("1233333") = False

Views 94

Downloads 52

CodeID
DB ID