Can I check the IMEI number?

For the mobile store application, I need to confirm the IMEI number . I know how to check based on input length, but is there any other mechanism for checking input number? Is there a built-in function that can achieve this?

Logic from any language is accepted and appreciated.

+6
source share
4 answers

The search assumes that there is no built-in function that will check the IMEI number, but there is a verification method using the Luhn algorithm .

General process:

  • IMEI Input: 490154203237518
  • : 49015420323751 8. 8 .
  • IMEI: 4 18 0 2 5 8 2 0 3 4 3 14 5 2 ( )
  • : 4 1 8 0 2 5 8 2 0 3 4 3 1 4 5 2 ( , 18 14 ).
  • : 4+1+8+0+2+5+8+2+0+3+4+3+1+4+5+2= 52
  • , : 60.
  • : 60 - 52= 8.
  • . , IMEI .

IMEI, 1 , , , 7, 8, .

+19

, Java.

public static int validateImei(String imei) {

    //si la longitud del imei es distinta de 15 es invalido
    if (imei.length() != 15)
        return CheckImei.SHORT_IMEI;

    //si el imei contiene letras es invalido
    if (!PhoneNumber.allNumbers(imei))
        return CheckImei.MALFORMED_IMEI;

    //obtener el ultimo digito como numero
    int last = imei.charAt(14) - 48;

    //duplicar cada segundo digito
    //sumar cada uno de los digitos resultantes del nuevo imei
    int curr;
    int sum = 0;
    for (int i = 0; i < 14; i++) {
        curr = imei.charAt(i) - 48;
        if (i % 2 != 0){
            // sum += duplicateAndSum(curr);
            // initial code from Osvel Alvarez Jacomino contains 'duplicateAndSum' method.
            // replacing it with the implementation down here:
            curr = 2 * curr;
            if(curr > 9) {
                curr = (curr / 10) + (curr - 10);
            }
            sum += curr;
        }
        else {
            sum += curr;
        }

    }

    //redondear al multiplo de 10 superior mas cercano
    int round = sum % 10 == 0 ? sum : ((sum / 10 + 1) * 10);

    return (round - sum == last) ? CheckImei.VALID_IMEI_NO_NETWORK : CheckImei.INVALID_IMEI;

}
+1

I do not believe that there are built-in ways to authenticate IMEI numbers. You will need to check the database of third-party developers (a search on Google suggests that there are a number of such services, but apparently they also receive information from more centralized sources).

0
source

I think this logic is not correct, because it only works for a specific IMEI no - 490154203237518 is not for other IMEIs ... I am implementing the code as well ...

var number = 490154203237518;
var array1 = new Array();
var array2 = new Array();
var specialno = 0 ;
var sum = 0 ;
var finalsum = 0;
var cast = number.toString(10).split('');
var finalnumber = '';
if(cast.length == 15){
    for(var i=0,n = cast.length; i<n; i++){

        if(i !== 14){
          if(i == 0 || i%2 == 0 ){
            array1[i] = cast[i];
          }else{
            array1[i] = cast[i]*2;
          }
        }else{
           specialno = cast[14];
        }

     }

     for(var j=0,m = array1.length; j<m; j++){
        finalnumber = finalnumber.concat(array1[j]);
     }

     while(finalnumber){
        finalsum += finalnumber % 10;
        finalnumber = Math.floor(finalnumber / 10);
     }

    contno = (finalsum/10);
    finalcontno = Math.round(contno)+1;

    check_specialno = (finalcontno*10) - finalsum; 

    if(check_specialno == specialno){
        alert('Imei')
    }else{
        alert('Not IMEI');
    }
}else{
    alert('NOT imei - length not matching');
}   


 //alert(sum);
0
source

All Articles