Skip to content

Instantly share code, notes, and snippets.

@lucnap
Created August 31, 2017 16:05
Show Gist options
  • Save lucnap/9583d99efbf1cfd2b03dd45703ba9b12 to your computer and use it in GitHub Desktop.
Save lucnap/9583d99efbf1cfd2b03dd45703ba9b12 to your computer and use it in GitHub Desktop.
imei validation function php
<?php
function validate_imei($imei)
{
if (!preg_match('/^[0-9]{15}$/', $imei)) return false;
$sum = 0;
for ($i = 0; $i < 14; $i++)
{
$num = $imei[$i];
if (($i % 2) != 0)
{
$num = $imei[$i] * 2;
if ($num > 9)
{
$num = (string) $num;
$num = $num[0] + $num[1];
}
}
$sum += $num;
}
if ((($sum + $imei[14]) % 10) != 0) return false;
return true;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment