Click here to Skip to main content
11,481,838 members (63,559 online)
Click here to Skip to main content

Tagged as

Mobile IMEI Validation

, 21 Dec 2011 CPOL 4K 1
Rate this:
Please Sign up or sign in to vote.
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):

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)

Share

About the Author

danlobo

Brazil Brazil
No Biography provided

Comments and Discussions

 
GeneralAlternate Accepted --RA Pin
Rajesh Anuhya27-Jan-12 3:48
memberRajesh Anuhya27-Jan-12 3:48 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 21 Dec 2011
Article Copyright 2011 by danlobo
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid