Skip to content

Instantly share code, notes, and snippets.

@NimzyMaina
Last active February 3, 2020 10:07
Show Gist options
  • Save NimzyMaina/aaa66595b1a421b6879b8da212ed170b to your computer and use it in GitHub Desktop.
Save NimzyMaina/aaa66595b1a421b6879b8da212ed170b to your computer and use it in GitHub Desktop.
Kenya Identify Network Service Provider
<?php
$phone = "0748123456"; // safaricom
//$phone = "+254789123456"; // airtel
$safaricom = "/(+?254|0|^){1}[-. ]?[7]{1}([0-2]{1}[0-9]{1}|[5|9]{1}[0-9]{1}|[4]{1}[0-4]{1}|[4]{1}[6|8]{1})[0-9]{6}z/";
$equitel = "/(\+?254|0|^){1}[-. ]?[7]{1}([6]{1}[3-5]{1})[0-9]{6}\z/";
$airtel = "/(\+?254|0|^){1}[-. ]?[7]{1}([3]{1}[0-9]{1}|[5]{1}[0-6]{1}|[8]{1}[0-2|5-9]{1})[0-9]{6}\z/";
$telcom = "/(\+?254|0|^){1}[-. ]?[7]{1}([7]{1}[0-9]{1})[0-9]{6}\z/";
if(preg_match($safaricom, $phone)){
echo 'SAFARICOM';
}else if(preg_match($airtel, $phone)) {
echo 'AIRTEL';
}else if(preg_match($equitel, $phone)) {
echo 'EQUITEL';
}else if(preg_match($telcom, $phone)) {
echo 'TELCOM';
}else {
echo "UNKNOWN";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment