没有任何人知道如何检查一个有效的IMEI?

我已经找到了一个函数来检查这个页面上: HTTP ://www.dotnetfunda.com/articles/article597-imeivalidator-in-vbnet-.aspx

但它返回有效的IMEI的指标(如false352972024585360。 我可以在网上验证它们在本页面: http://www.numberingplans.com/?page =分析&子= imeinr

什么是正确的方式(在VB.Net)检查,如果给定的IMEI是有效的?

PS: 此从上述网页功能必须是不正确的以某种方式:

Public Shared Function isImeiValid(ByVal IMEI As String) As Boolean
    Dim cnt As Integer = 0
    Dim nw As String = String.Empty
    Try
        For Each c As Char In IMEI
            cnt += 1
            If cnt Mod 2 <> 0 Then
                nw += c
            Else
                Dim d As Integer = Integer.Parse(c) * 2 ' Every Second Digit has to be Doubled '
                nw += d.ToString() ' Genegrated a new number with doubled digits '
            End If
        Next
        Dim tot As Integer = 0
        For Each ch As Char In nw.Remove(nw.Length - 1, 1)
            tot += Integer.Parse(ch) ' Adding all digits together '
        Next
        Dim chDigit As Integer = 10 - (tot Mod 10) ' Finding the Check Digit my Finding the Remainder of the sum and subtracting it from 10 '
        If chDigit = Integer.Parse(IMEI(IMEI.Length - 1)) Then ' Checking the Check Digit with the last digit of the Given IMEI code '
            Return True
        Else
            Return False
        End If
    Catch ex As Exception
        Return False
    End Try
End Function

修改:这是我的工作 “checkIMEI” - 功能:

Public Shared Function checkIMEI(ByRef IMEI As String) As Boolean
    Const allowed As String = "0123456789"

    Dim cleanNumber As New System.Text.StringBuilder
    For i As Int32 = 0 To IMEI.Length - 1
        If (allowed.IndexOf(IMEI.Substring(i, 1)) >= 0) Then
            cleanNumber.Append(IMEI.Substring(i, 1))
        End If
    Next

    If cleanNumber.Length <> 15 Then
        Return False
    Else
        IMEI = cleanNumber.ToString
    End If

    For i As Int32 = cleanNumber.Length + 1 To 16
        cleanNumber.Insert(0, "0")
    Next

    Dim multiplier As Int32, digit As Int32, sum As Int32, total As Int32 = 0
    Dim number As String = cleanNumber.ToString()

    For i As Int32 = 1 To 16
        multiplier = 1 + (i Mod 2)
        digit = Int32.Parse(number.Substring(i - 1, 1))
        sum = digit * multiplier
        If (sum > 9) Then
            sum -= 9
        End If
        total += sum
    Next

    Return (total Mod 10 = 0)
End Function
有帮助吗?

解决方案

IMEI号码使用验证了卢恩算法。所链接的页面有各种语言的实现。 这个帖子也有一些更多的实现,以及如何的一般方法着手解决Luhn算法。

其他提示

IMEISV(IMEI软件版本)不必Luhn算法校验位。相反,它的软件版本号呈现两位数字。 IMEI号码格式一直在不断发展多年。

维基百科是很好的来源,我认为通过几年看到的格式变化。如果你看看新的IMEI和IMEISV版本的格式,你会看到最后装配码(FAC)已经删除,类型分配码(TAC)增加了8位。有免费和商业TAC名单在互联网上存在。

这可能是通过对新老IMEI号卢恩算法验证的顶部仰视TAC列表的选项验证TAC号码。对于老IMEI号FAC为2位应该被丢弃和TAC验证应当为6位数字来完成。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top