<?php
$rightNumbers = 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' // нет +
);
$replacePattern = ['/\\s|-|\\(|\\)/u', //поиск "лишних" символов
'/^(\\+7)/u' //поиск +7
];
$replacement = ['','8'];
$checkPattern = '/^(8)\\d{10}$/'; //проверка номера
echo "ВЕРНЫЕ:\n";
foreach ($rightNumbers as $number){
$cleanStr = preg_replace($replacePattern, $replacement, $number); echo "$number ($cleanStr) верный - ok\n";
} else {
echo "$number ($cleanStr) неверный - ОШИБКА\n";
}
}
echo "НЕВЕРНЫЕ:\n";
foreach ($wrongNumbers as $number){
$cleanStr = preg_replace($replacePattern, $replacement, $number); echo "$number ($cleanStr) верный - ОШИБКА\n";
} else {
echo "$number ($cleanStr) неверный - ok\n";
}
}
PD9waHAKJHJpZ2h0TnVtYmVycyA9IGFycmF5KCc4NDk1MTIzNDU2NycsICcrNzQ5NTEyMzQ1NjcnLCAnOC00OTUtMS0yMzQtNTY3JywgJyA4ICg4MTIyKSA1Ni01Ni01NicsIAoJCQkJCSc4LTkxMS0xMjM0NTY3JywgJzggKDkxMSkgMTIgMzQ1IDY3JywgJzgtOTExIDEyIDM0NSA2NycsICc4ICg5MTEpIC0gMTIzIC0gNDUgLSA2NycsIAoJCQkJCScrIDcgOTk5IDEyMyA0NTY3JywgJzggKCA5OTkgKSAxMjM0NTY3JywgJzggOTk5IDEyMyA0NTY3Jyk7CiR3cm9uZ051bWJlcnMgPSBhcnJheSgnMDInLCAnODQ5NTEyMzQ1Njcg0L/QvtC30LLQsNGC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