function isCellphoneNumber($tel) {
// Remove all non relevant characters
$tel = preg_replace("/[^0-9\+]/", '', $tel);
$number = '';
$countryCode = 0;
if (preg_match("/^\+\d{2}/", $tel)) {
// Number with country code with trailing +
$countryCode = substr($tel, 1, 2);
$number = substr($tel, 3, strlen($tel) - 3);
$number = "00".$countryCode.$number;
} elseif (preg_match("/^00/", $tel)) {
// Country code present with trailing 00
$landesVorwahl = substr($tel, 2, 2);
$number = substr($tel, 4, strlen($tel) - 2);
$number = "00".$landesVorwahl.$number;
}
switch ((int) $countryCode) {
default:
case 49: // Germany
$netzvorwahlen = array(
'0151', '0160',
'0170', '0171', '0175', '0151',
'01520', '0162', '0172', '0173',
'0174', '0152', '0157', '01570',
'01577', '0163', '0177', '0178',
'0155', '0159', '0176', '0179'
);
break;
case 43: // Austria
$netzvorwahlen = array(
'0664',
'0676',
'0650',
'0699'
);
break;
case 41: // Swiss
$netzvorwahlen = array(
'079',
'076',
'078',
'077'
);
break;
case 29: // Spanien
$netzvorwahlen = array('6'); // In ESP beginnen alle Handynummern mit einer 6
break;
}
foreach ($netzvorwahlen as $vorwahl)
{
$vorwahl = preg_replace("/^0/", '', $vorwahl);
if (preg_match("/^00${landesVorwahl}${vorwahl}/", $nummer))
{
$tel = $nummer;
return true;
}
}
return false;
}
This function only supports cellphone numbers for the german speaking part of europe (swiss, germany, austria).
Tags
cellphone number php verify
Most popular snippets