<?php
$correctNumbers = array('84951234567', '+74951234567', '8-495-1-234-567', ' 8 (8122) 56-56-56', '8-911-1234567', '8 (911) 12 345 67', '8-911 12 345 67', '8 (911) - 123 - 45 - 67', '+ 7 999 123 4567', '8 ( 999 ) 1234567', '8 999 123 4567'); $wrongNumbers = array('02', '84951234567 позвать люсю', '849512345', '849512345678', '8 (409) 123-123-123', '7900123467', '5005005001', '8888-8888-88',
'84951a234567', '8495123456a',
'+1 234 5678901', // неверный код страны
'+8 234 5678901', // либо 8 либо +7'7 234 5678901' // нет +
);
$testNumber = '+7-(911)-50-65-656';
$regexp = '/^([+] 7|[+]7| 8|8)([(]|[)]|-| )*(\\d([(]|[)]|-| )*){9}\\d$/u';
$regexpOne = '/[+] 7|[+]7/';
$regexpTwo = '/[^0-9]/';
for ($i = 0; $i < count($correctNumbers); $i++) { {
echo "Номер {$correctNumbers[$i]} ";
echo "набран правильно, ";
$result = preg_replace($regexpOne, '8', $correctNumbers[$i]); echo "единый формат: {$result}\n";
}
else {
echo "Номер {$correctNumbers[$i]} ";
echo "набран неправильно\n";
}
}
for ($i = 0; $i < count($wrongNumbers); $i++) { {
echo "Номер {$wrongNumbers[$i]} ";
echo "набран правильно, ";
echo "единый формат: {$result}\n";
}
else {
echo "Номер {$wrongNumbers[$i]} ";
echo "набран неправильно\n";
}
}
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwogCiRjb3JyZWN0TnVtYmVycyA9IGFycmF5KCc4NDk1MTIzNDU2NycsICcrNzQ5NTEyMzQ1NjcnLCAnOC00OTUtMS0yMzQtNTY3JywgJyA4ICg4MTIyKSA1Ni01Ni01NicsICc4LTkxMS0xMjM0NTY3JywgJzggKDkxMSkgMTIgMzQ1IDY3JywgJzgtOTExIDEyIDM0NSA2NycsICc4ICg5MTEpIC0gMTIzIC0gNDUgLSA2NycsICcrIDcgOTk5IDEyMyA0NTY3JywgJzggKCA5OTkgKSAxMjM0NTY3JywgJzggOTk5IDEyMyA0NTY3Jyk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