<?php
$correctNumbers = [
'84951234567', '+74951234567', '8-49l5-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', '8 ( 999 ) 1234567',
'+1 234 5678901',
'+8 234 5678901',
'7 234 5678901'
];
$regexp = '/^(\+ *7| *8)([ ()-]*\d){10}$/m';
$correctValues = 0;
$incorrectValues = 0;
echo "Проверка правильных номеров:\n";
foreach ($correctNumbers as $number){
$correctValues++;
echo "[✓] $number правильно\n";
} else {
echo "[x] $number неправильно\n";
}
}
echo "\nПроверка неправильных номеров:\n";
foreach ($incorrectNumbers as $number){
$incorrectValues++;
echo "[x] $number неправильно\n";
} else {
echo "[✓] $number правильно\n";
}
}
$errorText = "сначала должно идти +7 или 8, за ними ровно 10 цифр, между которыми может быть любое число скобок, минусов, пробелов";
$result = (($correctValues == count($correctNumbers)) && ($incorrectValues == 0)) ?
"\nПроверка успешна" : "\nПроверка не успешна: ".$errorText; echo $result;
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwogCiRjb3JyZWN0TnVtYmVycyA9IFsgCiAgJzg0OTUxMjM0NTY3JywgICcrNzQ5NTEyMzQ1NjcnLCAnOC00OWw1LTEtMjM0LTU2NycsIAogICcgOCAoODEyMikgNTYtNTYtNTYnLCAnOC05MTEtMTIzNDU2NycsICc4ICg5MTEpIDEyIDM0NSA2NycsIAogICc4LTkxMSAxMiAzNDUgNjcnLCAnOCAoOTExKSAtIDEyMyAtIDQ1IC0gNjcnLCAnKyA3IDk5OSAxMjMgNDU2NycsIAogICc4ICggOTk5ICkgMTIzNDU2NycsICc4IDk5OSAxMjMgNDU2NycKXTsKJGluY29ycmVjdE51bWJlcnMgPS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