Created
August 31, 2017 16:05
-
-
Save lucnap/9583d99efbf1cfd2b03dd45703ba9b12 to your computer and use it in GitHub Desktop.
imei validation function php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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