fork(2) download
  1. <?php
  2.  
  3.  
  4. function numCheck($numArray) {
  5. foreach ($numArray as $id => $number) {
  6. $regexp = "/^\ ?((\+\ ?7)|8)\ ?(\(?\ ?\-?\d\ ?\)?){3,4}(\ ?\-?\ ?\d){6,7}$/";
  7. if (preg_match($regexp, $number)) {
  8. echo "+ {$number} \n";
  9. } else {
  10. echo "- {$number} \n";
  11. }
  12. }
  13. }
  14. $correctNumbers = [
  15. '8 ( 495 ) 1 - 2 - 3 - 4 - 5 - 6 - 7', '84951234567', '+74951234567', '8-495-1-234-567',
  16. ' 8 (8122) 56-56-56', '8-911-1234567', '8 (911) 12 345 67',
  17. '8-911 12 345 67', '8 (911) - 123 - 45 - 67', '+ 7 999 123 4567',
  18. '8 ( 999 ) 1234567', '8 999 123 4567'
  19. ];
  20. $incorrectNumbers = [
  21. '8 911 415 (16) (13)', '8 (((((((((((((((1938(((((2)((((21(((((21(((2', '8(((((((-------((((( ( --- ((((9(((1(((1)3------4----------5-----------6-----------7----((((8--------9)','02', '84951234567 позвать люсю', '849512345', '849512345678',
  22. '8 (409) 123-123-123', '7900123467', '5005005001', '8888-8888-88',
  23. '84951a234567', '8495123456a',
  24. '+1 234 5678901', /* неверный код страны */
  25. '+8 234 5678901', /* либо 8 либо +7 */
  26. '7 234 5678901' /* нет + */
  27. ];
  28. numCheck($correctNumbers);
  29. numCheck($incorrectNumbers);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
+ 8 ( 495 ) 1 - 2 - 3 - 4 - 5 - 6 - 7 
+ 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 
- 8 911 415 (16) (13) 
- 8 (((((((((((((((1938(((((2)((((21(((((21(((2 
- 8(((((((-------((((( ( --- ((((9(((1(((1)3------4----------5-----------6-----------7----((((8--------9) 
- 02 
- 84951234567 позвать люсю 
- 849512345 
+ 849512345678 
- 8 (409) 123-123-123 
- 7900123467 
- 5005005001 
+ 8888-8888-88 
- 84951a234567 
- 8495123456a 
- +1 234 5678901 
- +8 234 5678901 
- 7 234 5678901