Click here to Skip to main content
13,357,219 members (76,725 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 5 Jul 2012

IMEI validator using Java Swing

Rate this:
Please Sign up or sign in to vote.
How to create a simple IMEI validator application using Java Swing.


This document covers how to create a simple IMEI validator application using Java Swing.

IMEI Number

IMEI stands for International Mobile Equipment Identity. IMEI is used to identify a mobile device when it is connected to a network. Each GSM, CDMA, or satellite mobile has a unique IMEI number. This number will be printed in the device inside the battery component. A user can find his device IMEI number by calling “*#06#”. IMEI is a 15 digit number and the last digit is called as “Check Digit” and it can be identified by using Luhn algorithm.

Luhn algorithm

Luhn algorithm is also known as “Modulus 10” algorithm. It is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in US and Canadian Social Insurance Numbers. It was created by IBM scientist Hans Peter Luhn. Verification is done by validating check digit.

  1. Double the value of every second digit from the right end (first right will be check digit number).
  2. Add the individual digits comprising both the products from step (1) and unaffected digits in the original number.
  3. If the total modulo 10 is equal to 0, then the number is valid, else it is not valid.

A simple example: IMEI no of mobile-354557030810924

Step 1:

Step 2:


Step 3:

50%10=0. So above number is a valid number.

Steps to develop the application

  1. Open Eclipse and create a new Java project.
  2. Name the project as ImeiValidator and click Finish.
  3. Now open Package explorer and right click on ImeiValidator.
  4. Create new class called Imeivalidator.
  5. Write the following code in the class.
  6. import javax.swing.*;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    public class Imei {
          JFrame frame;
          JButton button;
          JTextField field;
          JLabel label;
          JLabel warninglabel;    
          Box panel;
          public static void main(String[] args) {
                Imei hl=new Imei();
          public void gui(){
                panel = Box.createVerticalBox();
                frame=new JFrame();
                button=new JButton("Click");
                field=new JTextField(15);
                field.putClientProperty("JComponent.sizeVariant", "mini");
                label=new JLabel("Enter the IMEI Number");
                warninglabel=new JLabel("");
                //adding contents to frame
                button.addActionListener(new buttonAction());
          public class buttonAction implements ActionListener{
               public void actionPerformed(ActionEvent ev) {
                     int sum=0;
                     String ImeiNo=field.getText();
                     if (ImeiNo.length()!=15){
                         warninglabel.setText("IMEI Number should contain 15 characters");
                         boolean errorflag = false;
                         for(int i=0;i<=14;i++){
                             //getting ascii value for each character
                             char c=ImeiNo.charAt(i);
                             int number=c;
                             //Assigning number values to corrsponding Ascii value
                             if (number<48 || number>57){
                                 warninglabel.setText("Enter only numerals");
                                 errorflag = true;
                                   case 48: number=0;break;
                                   case 49: number=1;break;
                                   case 50: number=2;break;
                                   case 51: number=3;break;
                                   case 52: number =4;break;
                                   case 53:number =5;break;
                                   case 54:number=6;break;
                                   case 55:number=7;break;
                                   case 56:number=8;break;
                                   case 57:number=9;break;
                             //Double the even number and divide it by 10. add quotient and remainder
                             if ((i+1)%2==0){
                     // Check the error flag to avoid overWriting of Warning Lable

  7. Now run the application by Run->Run As->Java Application.
  8. The following window will get displayed.
  9. Enter the IMEI number and click ‘Click’ as shown below.




This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Santhosh Kumar Jayaraman
Software Developer Radiometer
India India
Currently i am trying to learn all about javascripts . I have experience in Microsoft technologies like WPF, WCF, ASPNET, WinForms,Silverlight, VB.NET, C-Sharp, Entity framework,SSRS, LINQ, Extension methods and SQL server. I started with my career in Infosys in the year 2009 and i worked with Trigent, Education First (EF) in the recent years before joining my current company Radiometer.

You may also be interested in...


Comments and Discussions

SuggestionIMEI Validator using javafx and java Stream API Pin
Aamir Khan8-Nov-15 0:14
memberAamir Khan8-Nov-15 0:14 
SuggestionCode Improvements Pin
Psycho_Coder19-May-14 9:20
professionalPsycho_Coder19-May-14 9:20 
QuestionNice one Pin
umangm9-Jul-12 20:59
memberumangm9-Jul-12 20:59 
AnswerRe: Nice one Pin
Santhosh Kumar J5-Sep-12 22:25
memberSanthosh Kumar J5-Sep-12 22:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 5 Jul 2012
Article Copyright 2012 by Santhosh Kumar Jayaraman
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid