fork(1) download
  1. <?php
  2. $right = array('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', '02', '84951234567 позвать люсю', '849512345', '849512345678',
  3. '8 (409) 123-123-123', '7900123467', '5005005001', '8888-8888-88',
  4. '84951a234567', '8495123456a',
  5. '+1 234 5678901',
  6. '+8 234 5678901',
  7. '7 234 5678901'
  8. );
  9. $reg = '/\\s|-|[(]|[)]/';
  10. foreach ($right as &$value) {
  11. $value = preg_replace($reg, '', $value);
  12. }
  13. $regexp = '/^(8|[+]7)[0-9]{10}$/u';
  14. foreach ($right as $value) {
  15. if (preg_match($regexp, $value)) {
  16. echo "$value right number \n";
  17. }
  18. else
  19. {
  20. echo "$value wrong number \n";
  21. }
  22. }
  23. unset($value);
  24.  
Success #stdin #stdout 0.01s 24400KB
stdin
Standard input is empty
stdout
84951234567 right number 
+74951234567 right number 
84951234567 right number 
88122565656 right number 
89111234567 right number 
89111234567 right number 
89111234567 right number 
89111234567 right number 
+79991234567 right number 
89991234567 right number 
89991234567 right number 
02 wrong number 
84951234567позватьлюсю wrong number 
849512345 wrong number 
849512345678 wrong number 
8409123123123 wrong number 
7900123467 wrong number 
5005005001 wrong number 
8888888888 wrong number 
84951a234567 wrong number 
8495123456a wrong number 
+12345678901 wrong number 
+82345678901 wrong number 
+82345678901 wrong number