title: Check to see if string is an integer (includes negative numbers) PHP
body: <p>The function below checks if a string is an integer meaning it should only contain digits. But it does not check if number is negative (negative numbers should return true as well since they are integers). </p>
  
  <pre><code>function validateInteger($value)
  {
     //need is_numeric to avoid $value = true returns true with preg_match
     return is_numeric($value) &amp;&amp; preg_match('/^\d+$/', $value);
  }
  </code></pre>
  
  <p>I ran tests and got results:</p>
  
  <pre><code>'12.5'      =&gt; FALSE 
  12.5        =&gt; FALSE 
  'a125'      =&gt; FALSE 
  '125a'      =&gt; FALSE 
  '1a2.5'     =&gt; FALSE 
  125         =&gt; TRUE 
  'abc'       =&gt; FALSE 
  false       =&gt; FALSE 
  true        =&gt; FALSE 
  'false'     =&gt; FALSE 
  'true'      =&gt; FALSE 
  null        =&gt; FALSE 
  'null'      =&gt; FALSE 
  '1231'      =&gt; TRUE 
  -1231       =&gt; FALSE (SHOULD RETURN TRUE)
  '-1231'     =&gt; FALSE (SHOULD RETURN TRUE)
  </code></pre>
  
  <p>I dont want to use <code>itnval() &lt; 0</code>. I would prefer regular expression to check for negative numbers as well.</p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>I also have a function <code>validateFloat</code> that returns true if a given number is floating number meaning it can contain only <strong>digits</strong> and <strong>a dot</strong>. I need to apply same logic to this as well so that it returns true for <strong>negative floating numbers</strong></p>