Page 1 of 1

Checking country dialling code

Posted: Tue Feb 17, 2009 10:14 pm
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

Re: Checking country dialling code

Posted: Wed Feb 18, 2009 9:50 am
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";