note 77718 added to function.ctype-digit
| From: | minterior at gmail dot com | Date: | Mon, 10 Sep 2007 14:43:09 +0000 |
| Subject: | note 77718 added to function.ctype-digit | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130341@lists.php.net to get a copy of this message | ||
I use ctype_digit() function as a part of this IMEI validation function.
<?php
/**
* Check the IMEI of a mobile phone
* @param $imei IMEI to validate
*/
function is_IMEI_valid($imei){
if(!ctype_digit($imei)) return false;
$len = strlen($imei);
if($len != 15) return false;
for($ii=1, $sum=0 ; $ii < $len ; $ii++){
if($ii % 2 == 0) $prod = 2;
else $prod = 1;
$num = $prod * $imei[$ii-1];
if($num > 9){
$numstr = strval($num);
$sum += $numstr[0] + $numstr[1];
}else $sum += $num;
}
$sumlast = intval(10*(($sum/10)-floor($sum/10))); //The last digit of $sum
$dif = (10-$sumlast);
$diflast = intval(10*(($dif/10)-floor($dif/10))); //The last digit of $dif
$CD = intval($imei[$len-1]); //check digit
if($diflast == $CD) return true;
return false;
}
?>
----
Server IP: 80.64.47.13
Probable Submitter: 80.35.139.151
----
Manual Page -- http://www.php.net/manual/en/function.ctype-digit.php
Edit -- https://master.php.net/note/edit/77718
Del: integrated -- https://master.php.net/note/delete/77718/integrated
Del: useless -- https://master.php.net/note/delete/77718/useless
Del: bad code -- https://master.php.net/note/delete/77718/bad+code
Del: spam -- https://master.php.net/note/delete/77718/spam
Del: non-english -- https://master.php.net/note/delete/77718/non-english
Del: in docs -- https://master.php.net/note/delete/77718/in+docs
Del: other reasons-- https://master.php.net/note/delete/77718
Reject -- https://master.php.net/note/reject/77718
Search -- https://master.php.net/manage/user-notes.php