<?php
'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'
);
'+ 7(1234) - 1(2)3 - 123', // отсебятина: лишние скобки
'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' // нет +
);
function validatePhones
(array $numbers) {
//$regExp = '/^\s?(8|\+\s?7)\s?-?\s?\(?(\s?-?\s?\d\s?\)?\s?-?\s?){10}$/';
//$regExp = '/^\s?(8|\+\s?7)\s?-?\s?\(?(\s?-?\s?\d){3}\s?\)?(\s?-?\s?\d){7}\s?$/';
$regExp = '/^\s?(8|\+\s?7)\s?-?\s?\(?((\s?-?\s?\d){3}\s?\)?(\s?-?\s?\d){7}\s?|(\s?-?\s?\d){4}\s?\)?(\s?-?\s?\d){6}\s?)$/';
foreach ($numbers as $number) {
echo "+ Номер \"$number\" прошел проверку. +\n";
} else {
echo "- Номер \"$number\" НЕ прошел проверку. -\n";
}
}
echo "==================================================\n";
}
validatePhones($wrightNumbers);
validatePhones($wrongNumbers);
PD9waHAKCiR3cmlnaHROdW1iZXJzID0gYXJyYXkoCiAgICAnODQ5NTEyMzQ1NjcnLAogICAgJys3NDk1MTIzNDU2NycsCiAgICAnOC00OTUtMS0yMzQtNTY3JywKICAgICcgOCAoODEyMikgNTYtNTYtNTYnLAogICAgJzgtOTExLTEyMzQ1NjcnLAogICAgJzggKDkxMSkgMTIgMzQ1IDY3JywKICAgICc4LTkxMSAxMiAzNDUgNjcnLAogICAgJzggKDkxMSkgLSAxMjMgLSA0NSAtIDY3JywKICAgICcrIDcgOTk5IDEyMyA0NTY3JywKICAgICc4ICggOTk5ICkgMTIz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