<?php
function checkNumber($number) {
$regexp = '/^ ?(8|\\+ ?7)([()-\\s]*\\d){10}$/';
echo "Номер корректный\n";
} else {
echo "Неверный формат ввода\n";
}
}
$correct = 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');
$incorrect = 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' // нет +
);
foreach ($correct as $number) {
checkNumber($number);
}
echo "-------\n";
foreach ($incorrect as $number) {
checkNumber($number);
}
?>
PD9waHAKCWVycm9yX3JlcG9ydGluZygtMSk7CgkKCWZ1bmN0aW9uIGNoZWNrTnVtYmVyKCRudW1iZXIpIHsKCQkkcmVnZXhwID0gJy9eID8oOHxcXCsgPzcpKFsoKS1cXHNdKlxcZCl7MTB9JC8nOwoJCWlmIChwcmVnX21hdGNoKCRyZWdleHAsICRudW1iZXIpKSB7CgkJCWVjaG8gItCd0L7QvNC10YAg0LrQvtGA0YDQtdC60YLQvdGL0LlcbiI7CgkJfSBlbHNlIHsKCQkJZWNobyAi0J3QtdCy0LXRgNC90YvQuSDRhNC+0YDQvNCw0YIg0LLQstC+0LTQsFxuIjsKCQl9Cgl9CgoJJGNvcnJlY3QgPSBhcnJheSgnODQ5NTEyMzQ1NjcnLCAnKzc0OTUxMjM0NTY3JywgJzgtNDk1LTEtMjM0LTU2NycsICcgOCAoODEyMikgNTYtNTYtNTYnLCAnOC05MTEtMTIzNDU2NycsICc4ICg5MTEpIDEyIDM0NSA2NycsICc4LTkxMSAxMiAzNDUgNjcnLCAnOCAoOTExKSAtIDEyMyAtIDQ1IC0gNjcnLCAnKyA3IDk5OSAxMjMgNDU2NycsICc4ICggO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