fork(1) download
  1. <?php
  2.  
  3.  
  4. $regReplace = "/\W*/um";
  5. $regexp = "/^\s*(([+]\s*7)|8)([\s-()]*\d){10}[\s-()]*$/um";
  6. $firstNum = "/7|8/";
  7.  
  8. $correctNumbers = array();
  9. $incorrectNumbers = array();
  10.  
  11. $numbers = array( '84951234567', '+74951234567', '8-495-1-234-567',
  12. ' 8 (8122) 56-56-56', '8-911-1234567', '8 (911) 12 345 67',
  13. '8-911 12 345 67', '8 (911) - 123 - 45 - 67', '+ 7 999 123 4567',
  14. '8 ( 999 ) 1234567', '8 999 123 4567','02', '84951234567 позвать люсю', '849512345', '849512345678',
  15. '8 (409) 123-123-123', '7900123467', '5005005001', '8888-8888-88',
  16. '84951a234567', '8495123456a',
  17. '+1 234 5678901',
  18. '+8 234 5678901',
  19. '7 234 5678901' );
  20.  
  21. foreach ($numbers as $num) {
  22. if (preg_match($regexp, $num)) {
  23. $correctNumbers[] = $num;
  24. }
  25. }
  26.  
  27. $withoutAll = array();
  28.  
  29. foreach ($correctNumbers as $corrNum) {
  30. $withoutAll[] = preg_replace($regReplace,'',$corrNum);
  31.  
  32. }
  33.  
  34. $normalView = [];
  35.  
  36. foreach ($withoutAll as $plusSeven) {
  37. $normalView[] = preg_replace($firstNum,'+7',$plusSeven, 1);
  38. }
  39. echo "Верные номера \n";
  40. print_r($normalView);
  41.  
  42. foreach ($numbers as $num) {
  43. if (preg_match($regexp, $num)) {
  44. }
  45. else {
  46. $worngNum[] = $num;
  47. }
  48. }
  49.  
  50.  
  51. echo "Неверные \n";
  52. print_r($worngNum);
  53.  
  54.  
  55.  
  56. ?>
  57.  
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
Верные номера 
Array
(
    [0] => +74951234567
    [1] => +74951234567
    [2] => +74951234567
    [3] => +78122565656
    [4] => +79111234567
    [5] => +79111234567
    [6] => +79111234567
    [7] => +79111234567
    [8] => +79991234567
    [9] => +79991234567
    [10] => +79991234567
)
Неверные 
Array
(
    [0] => 02
    [1] => 84951234567 позвать люсю
    [2] => 849512345
    [3] => 849512345678
    [4] => 8 (409) 123-123-123
    [5] => 7900123467
    [6] => 5005005001
    [7] => 8888-8888-88
    [8] => 84951a234567
    [9] => 8495123456a
    [10] => +1 234 5678901
    [11] => +8 234 5678901
    [12] => 7 234 5678901
)