Compruebe si el IMEI válido
Pregunta
¿Alguien sabe cómo comprobar si hay un IMEI válido?
He encontrado una función para comprobar en esta página: http : //www.dotnetfunda.com/articles/article597-imeivalidator-in-vbnet-.aspx
Pero vuelve a false
(352972024585360
F. E.) del IMEI válido.
Puedo validar ellos en línea en esta página: http://www.numberingplans.com/?page = análisis y sub = imeinr
¿Cuál es la forma correcta (en VB.Net) para comprobar si un determinado IMEI es válida?
PS: Esta función de la página anterior debe ser incorrecta de alguna manera:
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
Editar : Este es mi trabajo "checkIMEI" -Función:
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
Otros consejos
IMEISV (versión de software IMEI) no tiene Luhn algoritmo de verificación de dígitos. En cambio, ha presentado Software número de versión con dos dígitos. Formato de número IMEI se ha estado desarrollando por años.
Wikipedia es la fuente buen pienso para ver los cambios en el formato de años. Si se mira el nuevo formato de la versión de IMEI y IMEISV, verías que el Código de Montaje Final (FAC) ha retirado y el tipo de asignación de código (TAC) fue aumentado el 8 dígitos. Hay libre y existen listas de TAC comerciales en Internet.
podría ser una opción para validar el número de TAC por buscar las listas de TAC en la parte superior de la validación algoritmo de Luhn para los nuevos y viejos números de IMEI. Para viejo números IMEI FAC como 2 dígitos debe ser desechada y validación TAC debe hacerse por 6 dígitos.