title: php: echo an error message
body: <p>code : </p>
  
  <pre><code>$searchText = '3423,  2453,  3245  ,  2425,  6765';     
  
  $numbers = str_replace(", ", ",", $searchText);
  
      $code = explode(",", $numbers);
  
     if ( (preg_match("/[^0-9]/i"), $code) || (strlen($code) != 4) ) {
  
              $searchingError= 'Can not cantain string and more than 4 digists number!';
              echo '&lt;script type="text/javascript"&gt;';
              echo "alert('" . $searchingError . "')";
              echo "&lt;/script&gt;";   
      }   
  
      function validate ($a) {
      if (ctype_digit($a) &amp;&amp; (strlen($a) == 4)) { 
          return "'$a'" ;
      } else {
          //$searchingError= 'Can not cantain string and more than 4 digists number!';
          //echo '&lt;script type="text/javascript"&gt;';
          //echo "alert('" . $searchingError . "')";
          //echo "&lt;/script&gt;";         
      }
  }
  
  $parsed = array_map( "validate",$code);
  
  print_r($parsed);
  
  $code = '(' . preg_replace('/\,+/', ',',implode(',', $parsed)) . ')';
  
  echo '&lt;br /&gt;' . $code;
  </code></pre>
  
  <p>In this code, is there a way to identify $searchText have only 4 digits numbers or it contain string etc. If it's so, I want to echo an error message. </p>
  
  <p>Thanks for any comments.</p>