title: test if a form input is a 1 or 2 digit integer with jquery and php
body: <p>I have a form that has five fields that are all set to maxlength="2".</p>
  
  <p>Basically, i want the only values that can be entered to either be a one or two digit integer, because calculations are performed on these fields before the values are stored in the database.</p>
  
  <p>Is there any jquery that will not let a user even enter a value that isnt an integer?</p>
  
  <p>Also what would be the best way to validate this with both jquery and php?  I have found some ways of doing it, but i need to make sure its secure, avoiding characters, -2, .1 etc</p>
  
  <hr>
  
  <p>SOLVED</p>
  
  <p>For the php part i used</p>
  
  <pre><code>if(!ctype_digit($_POST['value']))
  </code></pre>
  
  <p>which only allows for positive whole numbers</p>
  
  <p>And for javascript</p>
  
  <pre><code> $('.inputQuantity').keyup(function(){ 
      this.value = this.value.replace(/[^0-9\.]/g,'');
  });
  </code></pre>
  
  <p>which deletes any entry made into the input field that is not a number.</p>
  
  <p>Both above work, although i think some people prefer to use focusout(function() rather than keyup(function()   ;)</p>