fork download
  1. <?php
  2.  
  3.  
  4.  
  5. $corectNumbers = array('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. $reguexp = '/^[()+"\\s-]{0,4}(8|+7)[()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}[0-9][()+"\\s-]{0,4}$/';
  11.  
  12. for ($i = 0; $i <= count($corectNumbers)-1; $i++)
  13. {
  14. if (preg_match($reguexp, $corectNumbers[$i])){
  15. echo "Вы ввели правильный номер.\n";
  16. } else {
  17. echo "Введите номер ввиде: 8ABCXXXXXXX.\n";
  18. }
  19. }
  20. echo "Конец проверки правильных. \n";
  21.  
  22. $incorectNumbers = array('02', '84951234567 позвать люсю', '849512345', '849512345678',
  23. '8 (409) 123-123-123', '7900123467', '5005005001', '8888-8888-88',
  24. '84951a234567', '8495123456a',
  25. '+1 234 5678901', // неверный код страны
  26. '+8 234 5678901', // либо 8 либо +7
  27. '7 234 5678901' // нет +
  28. );
  29.  
  30. for ($i = 0; $i <= count($incorectNumbers)-1; $i++)
  31. {
  32. if (preg_match($reguexp, $incorectNumbers[$i])){
  33. echo "Вы ввели правильный номер.\n";
  34. } else {
  35. echo "Введите номер ввиде: 8ABCXXXXXXX.\n";
  36. }
  37. }
  38.  
  39. ?>
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Конец проверки правильных. 
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
Введите номер ввиде: 8ABCXXXXXXX.
stderr
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 16
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34
PHP Warning:  preg_match(): Compilation failed: nothing to repeat at offset 18 in /home/Recvor/prog.php on line 34