This article will explain how to validate a valid IMEI number of a mobile phone through VB.NET.
IMEI (International Mobile Equipment Identity) Code is a unique 15 Digit number which is usually found printed on the back side of the GSM/CDMA mobile phones battery.
The Logic behind identifying a correct IMEI Code is very simple.
The structure of the IMEI code is
AAAAAAAA - BBBBBB - C
AAAAAAAA = Type Allocation Code - The Type Allocation Code is an 8-digit number that identifies a particular model of wireless telephone for use on a GSM wireless network.
BBBBBB - Serial sequence of the model
And the most Important of All
C -The last number of the IMEI is a check digit calculated using the Luhn algorithm.
The check digit is validated in 3 steps:
- Starting from the right, double a digit every second digits (e.g., 8 ? 16).
- Sum the digits (e.g., 16 ? 1 + 6).
- Check if the sum is divisible by 10.
Conversely, one can calculate the IMEI by choosing the check digit that would give a sum divisible by 10. For the example IMEI 352048021523553,
|Double Every Second Digit
||3+1+0+2+0+4+1+6+0+4+1+1+0+2+6+5+1+0 = 37|
To make the sum divisible by 10, we set ? = 3, so the IMEI is .352048021523553
The reason I am writing this article is I had to develop a application for one of my client who was a mobile dealer and he had a requirement to check the IMEI of the mobiles he takes for sales or services.
Below is the code to Check a Valid IMEI code in VB.NET
In the TextBox Change Event of the TextBox where you want the user to enter the IMEI code type the following code.
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If TextBox1.Text.Length = 15 Then
Dim IMEI As String = TextBox1.Text
Dim cnt As Integer = 0
Dim nw As String = “” For Each c As Char In
IMEIcnt += 1
If cnt Mod 2 <> 0 Then
nw += c
Dim d As Integer = Integer.Parse(c) * 2nw += d.ToString()
End If Next Dim tot As Integer = 0
For Each ch As Char In nw.Remove(nw.Length - 1, 1)
Dim chDigit As Integer = 10 - (tot Mod 10)
If chDigit = Integer.Parse(IMEI(IMEI.Length - 1)) Then
Hope this article helped you.