Checking country dialling code

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
markthien
Forum Commoner
Posts: 33
Joined: Fri Feb 13, 2009 7:50 pm

Checking country dialling code

Post by markthien »

Hi guys,

I have just recently started to use php so kindda new kid on the block. My site will signup user using their mobile phone. Hence, when user enter their mobile phone number like 44123456789 or 353123456789123, where the first 2 digits (44) and first 3 digit (353) is the country dialling code. So how am I able to verify using php script if this 1st 2 or 3 digits is a valid country dialling code by given a list of like 250 valid country code?

Appreciate any help here please.

Thanks and reagrds,
Mark
mintedjo
Forum Contributor
Posts: 153
Joined: Wed Nov 19, 2008 6:23 am

Re: Checking country dialling code

Post by mintedjo »

Code: Select all

$number = "4412345674"; // get this from your user
 
$valid_codes = array("44", "34", "56", "67"); // List of valid codes
 
$code = substr($number, 0, 2); // get the first 2 digits
 
if(in_array($code, $valid_codes)) // check the array
    echo "VALID";
else
    echo "INVALID";
Post Reply