title: PHP: Best way to check if input is a valid number?
body: <p>What is the best way of checking if input is numeric?</p>
  
  <ul>
  <li>1-</li>
  <li>+111+</li>
  <li>5xf</li>
  <li>0xf</li>
  </ul>
  
  <p>Those kind of numbers should not be valid. Only numbers like: 123, 012 (12), positive numbers should be valid.
  This is mye current code:</p>
  
  <pre><code>$num = (int) $val;
  if (
      preg_match('/^\d+$/', $num)
      &amp;&amp;
      strval(intval($num)) == strval($num)
      )
  {
      return true;
  }
  else
  {
      return false;
  }
  </code></pre>