title: How to avoid entering special characters in JavaScript
body: <p>On html I have one input box in which I just want to enter numeric values. I used following function:</p>
  
  <pre><code>function allowNumbersOnly(event,locale) {
      if(locale=='en' &amp;&amp; (event.keyCode==190 || event.keyCode==110)){
          return true;
      }
      else if(locale=='nl' &amp;&amp; (event.keyCode==188 || event.keyCode==190 || event.keyCode==110)){
          return true;
      }
      if(event.keyCode==189 || (event.keyCode==109) ){
          return true;
      }
      var key = event.charCode || event.keyCode || 0;
  
      // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
      if (
          key == 8 || 
          key == 9 ||
          key == 46 ||
          (key &gt;= 37 &amp;&amp; key &lt;= 40) ||
          (key &gt;= 48 &amp;&amp; key &lt;= 57) ||
          (key &gt;= 96 &amp;&amp; key &lt;= 105)){
  
          }else{
               event.preventDefault();
  
              }
  }
  </code></pre>
  
  <p>This code works fine. But when I am pressing <code>shift key+ any number</code> from keyboard then special character gets entered. Can anyone tell me how to solve this issue? </p>