2 Replies - 1481 Views - Last Post: 01 March 2011 - 03:07 AM

#1 smshUA  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 07-June 07

IMEI validator

Posted 07 June 2007 - 08:11 AM

Description: Validates mobile's IMEI number. Returns true if IMEI is right.
function isIMEI (s) {
var etal = /^[0-9]{15}$/;
  if (!etal.test(s))
    return false;
  sum = 0; mul = 2; l = 14;
  for (i = 0; i < l; i++) {
    digit = s.substring(l-i-1,l-i);
    tp = parseInt(digit,10)*mul;
    if (tp >= 10)
         sum += (tp % 10) +1;
    else
         sum += tp;
    if (mul == 1)
         mul++;
    else
         mul--;
    }
  chk = ((10 - (sum % 10)) % 10);
  if (chk != parseInt(s.substring(14,15),10))
    return false;
  return true;
}



Is This A Good Question/Topic? 0
  • +

Replies To: IMEI validator

#2 sdm9201  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 03-December 09

Re: IMEI validator

Posted 10 December 2009 - 12:18 PM

could you give me some examples of how this could used ? thanks sdm9201
Was This Post Helpful? 0
  • +
  • -

#3 josh06  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 139
  • Joined: 27-October 06

Re: IMEI validator

Posted 01 March 2011 - 03:07 AM

Just run the function like so: if(!isIMEI(imei number here)){ // code if false }else{ // code if true }
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1