Last updated on August 1st, 2015 at 04:37 pm

In this tip is share a IMEI number validator function with you this is simple and efficient method which i create to validate mobile IMEI number. Some time for security reason or make or application more secure we validate request comming from which device and also read some information of device at that time we also validate IMEI number of device which come from our mobile application.

PHP Method to Validate IMEI

<?php
function valid_imei($number){
	$getLastNumber = substr($number, strlen($number)-1);
	$getRemaining = substr($number, 0, strlen($number)-1);
	$getRemainLength = strlen($getRemaining);
	$getEvenAndDouble = array();
	for($i=0; $i < $getRemainLength; $i++){
		if($i%2){
			$getEvenAndDouble[] = substr($getRemaining, $i, 1)*2;
		}else{
			$getEvenAndDouble[] = substr($getRemaining, $i, 1);
		}
	}
	$sumEven = array();
	for($i = 0; $i < $getRemainLength; $i++){
		if($i%2){
			$splitTwoAndAdd = substr($getEvenAndDouble[$i], 0, 1) + substr($getEvenAndDouble[$i], 1); 
			$getEvenAndDouble[$i] = $splitTwoAndAdd;
		}
	}
	$lastSum = array_sum($getEvenAndDouble);
	$findMod = $lastSum%10;
	if($findMod != 0)
		$checksum = 10 - $findMod;
	else 
		$checksum = $findMod;

	return ($checksum == $getLastNumber) ? true : false;
}
?>

Hope this help some one :-).