Check for valid IMEI
Posted
by Tim
on Stack Overflow
See other posts from Stack Overflow
or by Tim
Published on 2010-03-25T14:59:32Z
Indexed on
2010/03/25
15:03 UTC
Read the original article
Hit count: 540
Hi,
does somebody knows how to check for a valid IMEI?
I have found a function to check on this page: http://www.dotnetfunda.com/articles/article597-imeivalidator-in-vbnet-.aspx
But it returns false for valid IMEI's (f.e. 352972024585360). I can validate them online on this page: http://www.numberingplans.com/?page=analysis&sub=imeinr
What is the correct way(in VB.Net) to check if a given IMEI is valid?
Regards, Tim
PS: This function from above page must be incorrect in some way:
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
© Stack Overflow or respective owner