fork download
  1. <?php
  2.  
  3.  
  4. $numbers = array('84951234567',
  5. '+74951234567',
  6. '8-495-1-234-567',
  7. ' 8 (8122) 56-56-56',
  8. '8-911-1234567',
  9. '8 (911) 12 345 67',
  10. '8-911 12 345 67',
  11. '8 (911) - 123 - 45 - 67',
  12. '+ 7 999 123 4567',
  13. '8 ( 999 ) 1234567',
  14. '8 999 123 4567',
  15. '02', '84951234567 позвать люсю', '849512345', '8495123456789999',
  16. '8 (409) 123-123-123', '7900123467', '5005005001', '8888-8888-88',
  17. '84951a234567', '8495123456a',
  18. '+1 234 5678901', // неверный код страны
  19. '+8 234 5678901', // либо 8 либо +7
  20. '7 234 5678901' // нет +
  21. );
  22.  
  23.  
  24. $regexp = '/^(8|\\+7)([0-9 \\-?\\(?\s?\\)?]{10})/u';
  25.  
  26. foreach($numbers as $value){
  27. if(preg_match($regexp, $value)){
  28. echo "Etot nomer verniy {$value}\n";
  29. }else {
  30. echo "Etot nomer neverniy - ALLAHU AKBAR {$value}\n";
  31. }
  32. }
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Etot nomer verniy 84951234567
Etot nomer verniy +74951234567
Etot nomer verniy 8-495-1-234-567
Etot nomer neverniy - ALLAHU AKBAR  8 (8122) 56-56-56
Etot nomer verniy 8-911-1234567
Etot nomer verniy 8 (911) 12 345 67
Etot nomer verniy 8-911 12 345 67
Etot nomer verniy 8 (911) - 123 - 45 - 67
Etot nomer neverniy - ALLAHU AKBAR + 7 999 123 4567
Etot nomer verniy 8 ( 999 ) 1234567
Etot nomer verniy 8 999 123 4567
Etot nomer neverniy - ALLAHU AKBAR 02
Etot nomer verniy 84951234567 позвать люсю
Etot nomer neverniy - ALLAHU AKBAR 849512345
Etot nomer verniy 8495123456789999
Etot nomer verniy 8 (409) 123-123-123
Etot nomer neverniy - ALLAHU AKBAR 7900123467
Etot nomer neverniy - ALLAHU AKBAR 5005005001
Etot nomer verniy 8888-8888-88
Etot nomer neverniy - ALLAHU AKBAR 84951a234567
Etot nomer neverniy - ALLAHU AKBAR 8495123456a
Etot nomer neverniy - ALLAHU AKBAR +1 234 5678901
Etot nomer neverniy - ALLAHU AKBAR +8 234 5678901
Etot nomer neverniy - ALLAHU AKBAR 7 234 5678901