<?php
$correctNumbers = [
'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'
];
$incorrectNumbers = [
'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' /* нет + */
];
$regexp = "/^(\+\s?7|\s?8)([\s\(\)\-]*\d){10}$/";
foreach (array_merge($correctNumbers, $incorrectNumbers) as $numbers ) { echo "Номер {$numbers} - верный\n";
}
else {
echo "Номер {$numbers} - неверный\n";
}
}
PD9waHAKCiRjb3JyZWN0TnVtYmVycyA9IFsgCiAgJzg0OTUxMjM0NTY3JywgICcrNzQ5NTEyMzQ1NjcnLCAnOC00OTUtMS0yMzQtNTY3JywgCiAgJyA4ICg4MTIyKSA1Ni01Ni01NicsICc4LTkxMS0xMjM0NTY3JywgJzggKDkxMSkgMTIgMzQ1IDY3JywgCiAgJzgtOTExIDEyIDM0NSA2NycsICc4ICg5MTEpIC0gMTIzIC0gNDUgLSA2NycsICcrIDcgOTk5IDEyMyA0NTY3JywgCiAgJzggKCA5OTkgKSAxMjM0NTY3JywgJzggOTk5IDEyMyA0NTY3JwpdOwokaW5jb3JyZWN0TnVtYmVycyA9IFsKICAnMDInLCAnODQ5NTEyMzQ1Njcg0L/QvtC30LLQsNGC0Ywg0LvRjtGB0Y4nLCAnODQ5NTEyMzQ1JywgJzg0OTUxMjM0NTY3OCcsIAogICc4ICg0MDkpIDEyMy0xMjMtMTIzJywgJzc5MDAxMjM0NjcnLCAnNTAwNTAwNTAwMScsICc4ODg4LTg4ODgtODgnLAogICc4NDk1MWEyMzQ1NjcnLCAnODQ5NTEyMzQ1NmEnLCAKICAnKzEgMjM0IDU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