validPhone - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of validPhone.php

  1. <?php
  2.  
  3.         function ValidPhone($phone) {
  4.                 $valid = false;
  5.                         if (!is_string($phone)) {
  6.                                 $valid = true;
  7.                                 echo 'is_string true';
  8.                         }
  9.                         if (!preg_match('/((8|\+7)-?)?\(?\d{3,5}\)?-?\d{1}-?\d{1}-?\d{1}-?\d{1}-?\d{1}((-?\d{1})?-?\d{1})?/', $phone)) {
  10.                                 $valid = true;
  11.                                 echo 'preg_match true';
  12.                         }
  13.                        
  14.                         if ( strlen($phone)<=7 && strlen($phone)>=12 ) {
  15.                                 $valid = true;
  16.                                 echo 'strlen true';
  17.                         }
  18.                 if ( $valid ) {
  19.                                                 return true;
  20.                 }
  21.                                                 return false;
  22.         }
  23.  
  24. var_dump(ValidPhone('109062667234234467'));
  25. ?>
File Description
  • validPhone
  • PHP Code
  • 08 Aug-2022
  • 519 Bytes
You can Share it: