fork(1) download
  1. <?php
  2.  
  3.  
  4. function checkN($string){
  5. $reg='/^((\+\s?7\s?)|(\s?8(\W)?))((\W+)?\d(\W)?){10}$/';
  6. if(preg_match($reg,$string)){return true;}
  7. else {return false;}
  8.  
  9. }
  10. //tests
  11. $testArray=['84951234567','+74951234567','8-495-1-234-567','8 (8122) 56-56-56','
  12. 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',
  13. '8 999 123 4567'];
  14. for ($i=0;$i<count($testArray);$i++){
  15. if (!checkN($testArray[$i])){echo "Error in {$testArray[$i]}";break;}
  16. else {echo "Ok\n";}
  17. }
  18. $falseArray=['02','84951234567 позвать люсю','849512345','849512345678','8 (409) 123-123-123','7900123467','5005005001',
  19. '8888-8888-88','84951a234567','8495123456a','+1 234 5678901','+8 234 5678901','7 234 5678901'];
  20. for ($i=0;$i<count($falseArray);$i++){
  21. if (checkN($falseArray[$i])){echo "Error in {$falseArray[$i]}";break;}
  22. else {echo "Ok\n";}}
  23. ?>
Success #stdin #stdout 0s 82624KB
stdin
Standard input is empty
stdout
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok
Ok