<?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' // нет +
);
$pattern = '/^[-\\(\\)\\s]*(\\+[-\\(\\)\\s]*7|8)[-\\(\\)\\s]*(\\d[-\\(\\)\\s]*){10}$/';
echo "ВЕРНЫЕ\n";
foreach ($rightNumbers as $number){
echo "{$number} - ok\n";
} else {
echo "{$number} - oшибка\n";
}
}
echo "НЕВЕРНЫЕ\n";
foreach ($wrongNumbers as $number){
echo "{$number} - верный - ошибка\n";
} else {
echo "{$number} - неверный - ok\n";
}
}
PD9waHAKJHJpZ2h0TnVtYmVycyA9IGFycmF5KCc4NDk1MTIzNDU2NycsICcrNzQ5NTEyMzQ1NjcnLCAnOC00OTUtMS0yMzQtNTY3JywgJyA4ICg4MTIyKSA1Ni01Ni01NicsIAoJCQkJCSc4LTkxMS0xMjM0NTY3JywgJzggKDkxMSkgMTIgMzQ1IDY3JywgJzgtOTExIDEyIDM0NSA2NycsICc4ICg5MTEpIC0gMTIzIC0gNDUgLSA2NycsIAoJCQkJCScrIDcgOTk5IDEyMyA0NTY3JywgJzggKCA5OTkgKSAxMjM0NTY3JywgJzggOTk5IDEyMyA0NTY3Jyk7CiR3cm9uZ051bWJlcnMgPSBhcnJheSgnMDInLCAnODQ5NTEyMzQ1Njcg0L/QvtC30LLQsNGC0Ywg0LvRjtGB0Y4nLCAnODQ5NTEyMzQ1JywgJzg0OTUxMjM0NTY3OCcsIAoJCQkJCSc4ICg0MDkpIDEyMy0xMjMtMTIzJywgJzc5MDAxMjM0Nj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