Last active
January 14, 2016 23:31
-
-
Save mocanuga/f648750f4344d4b41ce0 to your computer and use it in GitHub Desktop.
Validate Italy mobile phone numbers
This file contains hidden or 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
/** | |
* @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