<?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'
);
'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}$/';
foreach ($numbers as $number) {
echo "+ Номер \"$number\" прошел проверку. +\n";
} else {
echo "- Номер \"$number\" НЕ прошел проверку. -\n";
}
}
echo "==================================================\n";
}
validatePhones($wrightNumbers);
validatePhones($wrongNumbers);
PD9waHAKJHdyaWdodE51bWJlcnMgPSBhcnJheSgKICAgICc4NDk1MTIzNDU2NycsCiAgICAnKzc0OTUxMjM0NTY3JywKICAgICc4LTQ5NS0xLTIzNC01NjcnLAogICAgJyA4ICg4MTIyKSA1Ni01Ni01NicsCiAgICAnOC05MTEtMTIzNDU2NycsCiAgICAnOCAoOTExKSAxMiAzNDUgNjcnLAogICAgJzgtOTExIDEyIDM0NSA2NycsCiAgICAnOCAoOTExKSAtIDEyMyAtIDQ1IC0gNjcnLAogICAgJysgNyA5OTkgMTIzIDQ1NjcnLAogICAgJzggKCA5OTkgKSAxMjM0NTY3JywKICAgICc4IDk5OSAxMjMgNDU2NycKICAgICk7CiR3cm9uZ051bWJlcnMgPSBhcnJheSgKICAgICcwMicsCiAgICAnODQ5NTEyMzQ1Njcg0L/QvtC30LLQsNGC0Ywg0LvRjtGB0Y4nLAogICAgJzg0OTUxMjM0NScsCiAgICAnODQ5NTEyMzQ1Njc4JywKICAgICc4ICg0MDkpIDEyMy0xMjMtMTIzJywKICAgICc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