title: JQuery to allow only numeric input in text box using key code
body: <p>I am trying to allow only numbers <strong>[0-9]</strong> to be typed in a text box. If an alpha or special character is typed, I do not want it to be shown in the text box. Currently my code is as follows:</p>
  
  <pre><code>$('#TEXTBOX').on("keydown", function(event){
      var keyCode = event.which;
      if(!((keyCode &gt; 47 &amp;&amp; keyCode &lt; 58) ||  (keyCode &gt; 95 &amp;&amp; keyCode &lt; 106) ||  keyCode == 08)){
          event.preventDefault();
      }
  });
  </code></pre>
  
  <p>I am having a few problems. </p>
  
  <ol>
  <li><p>This function is still allows special characters <strong>[i.e (SHIFT + 1) gives !, (SHIFT + 2) gives @]</strong> I do not want these key combinations to allow insert into text box</p></li>
  <li><p>I am using magic numbers. I would prefer not to use magic numbers and logic but this is the only way I was able to get the input validation to work.... are there any suggestions on other methods?</p></li>
  </ol>
  
  <p>My main concern is my first problem with the special characters.</p>