Click here to Skip to main content
15,889,200 members
Articles / Mobile Apps
Alternative
Tip/Trick

Mobile IMEI Validation

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
21 Dec 2011CPOL 11.6K   1   1
There is my version, no use of int arrays. While the while instruction is a good approach in many cases, in this specific one, it is not necessary, since the bigger number will be 18 (9 * 2):private Boolean ValidateIMEI(string IMEI){ if (IMEI.Length != 15) return false; var sum...

There is my version, no use of int arrays. While the while instruction is a good approach in many cases, in this specific one, it is not necessary, since the bigger number will be 18 (9 * 2):


C#
private Boolean ValidateIMEI(string IMEI)
{
  if (IMEI.Length != 15)
    return false;

  var sum = 0;
  var pos = 0;
  foreach (var imeiChar in IMEI)
  {
    var imeiInt = int.Parse(imeiChar.ToString());
    if (pos % 2 != 0) imeiInt *= 2;
    if (imeiInt > 9) imeiInt = (imeiInt % 10) + (imeiInt / 10);
    sum += imeiInt;
    ++pos;
  }
  return sum % 10 == 0;
}

License

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


Written By
Brazil Brazil
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralAlternate Accepted --RA Pin
Rajesh Anuhya27-Jan-12 2:48
professionalRajesh Anuhya27-Jan-12 2:48 

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.