Skip to content

Instantly share code, notes, and snippets.

@mocanuga
Last active January 14, 2016 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mocanuga/f648750f4344d4b41ce0 to your computer and use it in GitHub Desktop.
Save mocanuga/f648750f4344d4b41ce0 to your computer and use it in GitHub Desktop.
Validate Italy mobile phone numbers
/**
* @author mocanuga
* @desc Return the operator for a phone number for Italy
* @return string
*/
function phoneOperator ($phone) {
if(!preg_match('/((313)|(3[2-9]{1}[0-9]{1}))([0-9]{7})/', $phone)) // invalid Italy mobile number
return 'unkown';
$mobileOperators = array(
'/^313/' => 'Rete Ferroviaria Italiana',
'/^32/' => 'Wind Italy',
'/^33/' => 'TIM',
'/^34/' => 'Vodafone Italy',
'/^35/' => 'Future full-MVNO',
'/^36/' => 'TIM',
'/^37/' => 'Various ESP/MVNO',
'/^38/' => 'Wind Italy',
'/^39/' => 'H3G Italy'
);
$operatorKey = array_filter(array_keys($mobileOperators), function ($operator) use ($phone) {
return preg_match($operator, $phone);
});
return !empty($operatorKey) ? $mobileOperators[array_shift($operatorKey)] : 'unknown';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment