Click here to Skip to main content
12,348,846 members (40,387 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.9K views
1 bookmarked
Posted

Mobile IMEI Validation

, 21 Dec 2011 CPOL
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

You may also be interested in...

Comments and Discussions

 
GeneralAlternate Accepted --RA Pin
Rajesh Anuhya27-Jan-12 2:48
memberRajesh 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.

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