title: Restrict input to number only on pasting
body: <p>I have an input filed with a class called restrict-numbers which i want to restrict the entered characters to only accept numbers, i used the following code which is great but the problem that i want to make the same restriction works with pasting in the input filed without totally disabling pasting:</p>
  
  <pre><code>function input_only_numbers(){
  $("input[type=text]").each(function(){
  if( $(this).hasClass("restrict-numbers") ){    
      $(this).keydown(function(event) {
      if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || 
  
          // Allow: Ctrl+A
      (event.keyCode == 65 &amp;&amp; event.ctrlKey === true) ||
  
          // Allow: Ctrl+V
      (event.ctrlKey == true &amp;&amp; (event.which == '118' || event.which == '86')) ||
  
          // Allow: Ctrl+c
      (event.ctrlKey == true &amp;&amp; (event.which == '99' || event.which == '67')) ||
  
          // Allow: Ctrl+x
      (event.ctrlKey == true &amp;&amp; (event.which == '120' || event.which == '88')) ||
  
          // Allow: home, end, left, right
      (event.keyCode &gt;= 35 &amp;&amp; event.keyCode &lt;= 39)) {
      // let it happen, don't do anything
          return;
      }
      else {
      // Ensure that it is a number and stop the keypress
          if ( event.shiftKey|| (event.keyCode &lt; 48 || event.keyCode &gt; 57) &amp;&amp; (event.keyCode &lt; 96 || event.keyCode &gt; 105 ) ){
          event.preventDefault(); 
          }
      }
      });
  }
  
  
  
  
  });
  </code></pre>
  
  <p>}</p>