fork(1) download
  1. <?php
  2.  
  3.  
  4. $correctNumbers = [
  5. '84951234567', '+74951234567', '8-495-1-234-567',
  6. ' 8 (8122) 56-56-56', '8-911-1234567', '8 (911) 12 345 67',
  7. '8-911 12 345 67', '8 (911) - 123 - 45 - 67', '+ 7 999 123 4567',
  8. '8 ( 999 ) 1234567', '8 999 123 4567'
  9. ];
  10. $incorrectNumbers = [
  11. '02', '84951234567 позвать люсю', '849512345', '849512345678',
  12. '8 (409) 123-123-123', '7900123467', '5005005001', '8888-8888-88',
  13. '84951a234567', '8495123456a',
  14. '+1 234 5678901',
  15. '+8 234 5678901',
  16. '7 234 5678901'
  17. ];
  18. $regexp = '/^(\+ *7| *8)([ ()-]*\d){10}$/m';
  19.  
  20. $correctValues = 0;
  21. $incorrectValues = 0;
  22. foreach ($correctNumbers as $number){
  23. if (preg_match($regexp, $number)){
  24. $correctValues++;
  25. }
  26. }
  27. foreach ($incorrectNumbers as $number){
  28. if (preg_match($regexp, $number)){
  29. $incorrectValues++;
  30. }
  31. }
  32. $result = (($correctValues == count($correctNumbers)) && ($incorrectValues == 0)) ? "Проверка успешна" : "Проверка не успешна";
  33. echo $result;
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Проверка успешна