Created
May 21, 2019 08:39
-
-
Save snowbob/18887ec93a691dfaa355dbd7f60448d2 to your computer and use it in GitHub Desktop.
check if valid mobile phone number
This file contains 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 | |
$phones = array( '447549007599', '353852723831', '614549007599' , '615549007599' , '642549007599' , '918667672071'); | |
#$phones = array( '448549007599'); | |
function isValidMobileNumber($phones = null) { | |
$countryCode = array( '44' => '7', '353' => '8', '61' =>'4|5', '64' =>'2'); | |
$result = array(); | |
foreach( $phones as $number ) | |
{ | |
$country = array('STATUS' => 'INVALID', 'AREACODE' => '', 'NUMBER' => ''); | |
$country['NUMBER'] = $number; | |
foreach( $countryCode as $key => $value ) | |
{ | |
if ( substr( $number, 0, strlen( $key ) ) == $key ) { | |
if ( in_array(substr( $number, strlen( $key ) , 1 ), explode('|', $value)) ) { | |
$country['STATUS'] = "VALID"; | |
$country['AREACODE'] = $key; | |
break; | |
} | |
} | |
} | |
array_push($result, $country); | |
} | |
return $result; | |
} | |
print_r(isValidMobileNumber($phones)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment