title: Preg Match number
body: <p>I want to ensure that when a user enters a number on an online form, he HAS to enter a number between 1 and 5, and no other number should be valid. If the user enters "6" for example, he will be met with a message such as "please enter a number between 1 and 5 only". Could someone please tell me how I can code this in PHP? What I can think of is</p>
  
  <pre><code>               if (empty($_POST["number"])) {
       $numberErr = "Number is required";
           } else {
       $number = test_input($_POST["number"]);
       // check if number is between 1 and 5 inclusive
       if (!preg_match("/^[1-5 ]*$/",$number)) {
         $number = "";
         $numberErr = "Only a number between 1 and 5 is allowed";
  
       }
     }
  </code></pre>
  
  <p>But this seems too simplistic and wrong. Can someone please help?            </p>