title: Regex to validate only natural numbers?
body: <p>I recently found out that a method I've been using for validating user input accepts some values I'm not particularly happy with. I need it to only accept natural numbers (<code>1</code>, <code>2</code>, <code>3</code>, etc.) without non-digit characters.</p>
  
  <p>My method looks like this:</p>
  
  <pre><code>function is_natural($str)
  {
     return preg_match('/[^0-9]+$/', $str) ? false : $str;
  }
  </code></pre>
  
  <p>So it's supposed to return false if it finds anything else but a whole natural number. Problem is, it accepts strings like <code>"2.3"</code> and even <code>"2.3,2.2"</code></p>