Database Lunh算法在access中的应用
有人知道如何在access中应用Lahn算法,以便用电话号码验证参考号码此功能将为您计算校验位:Database Lunh算法在access中的应用,database,ms-access,luhn,Database,Ms Access,Luhn,有人知道如何在access中应用Lahn算法,以便用电话号码验证参考号码此功能将为您计算校验位: Public Function Modulus1x(ByVal strNum As String, ByVal intModulus As Integer) As Integer ' Creates the Modulus-10 or -11 check digit for strNum. ' Non-numeric characters are ignored. ' M
Public Function Modulus1x(ByVal strNum As String, ByVal intModulus As Integer) As Integer
' Creates the Modulus-10 or -11 check digit for strNum.
' Non-numeric characters are ignored.
' Maximum length of number.
Const cintNumLenMax = 31
Dim strTmp As String
Dim intChr As Integer
Dim intLen As Integer
Dim intSum As Integer
Dim intVal As Integer
Dim intWeight As Integer
Dim intCount As Integer
Dim intChk As Integer
Select Case intModulus
Case 10, 11
intLen = Len(strNum)
If intLen > 0 Then
' Remove non-numeric characters.
For intCount = 1 To intLen
intChr = Asc(Mid(strNum, intCount))
If intChr >= 48 And intChr <= 57 Then
strTmp = strTmp & Chr(intChr)
End If
Next intCount
strNum = strTmp
intLen = Len(strNum)
If intLen > 0 Then
' Calculate check digit.
If intLen <= cintNumLenMax Then
For intCount = 1 To intLen
intVal = Val(Mid(strNum, intLen - intCount + 1, 1))
Select Case intModulus
Case 10
intWeight = 1 + (intCount Mod 2)
intVal = intWeight * intVal
intVal = Int(intVal / 10) + (intVal Mod 10)
Case 11
intWeight = 2 + ((intCount - 1) Mod 6)
intVal = intWeight * intVal
End Select
intSum = intSum + intVal
Next intCount
intChk = -Int(-intSum / intModulus) * intModulus - intSum
End If
End If
End If
End Select
Modulus1x = intChk
End Function
使用此处的函数:
您可以使用CheckDigit验证电话号码我需要将Luhn算法插入“参考号码”字段,以便它为我们的Bpa y客户生成支票号码,如果没有正确的支票号码,他们将无法进行付款。支票号码是根据客户的“电话号码”生成的。我发现了这个代码。但是我不知道如何申请这个电话号码。我非常感谢你。你是最棒的
PhoneNumber = "+01234568790"
CheckDigit = Modulus1x(PhoneNumber, 10)
PhoneNumberWithCheckDigit = PhoneNumber & CheckDigit