title: How to allow only numbers (even when copy-pasted) in input text field using jQuery?
body: <p>I am using this jQuery code to allow only numbers to be entered in input text field.</p>
  
  <pre><code>jQuery(document).ready(function() {     
      jQuery( '.only_numbers' ).keydown(function (e) {
          // Allow: backspace, delete, tab, escape, enter and .
          if (jQuery.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
               // Allow: Ctrl+A, Command+A
              ((e.keyCode === 65) &amp;&amp; (e.ctrlKey === true || e.metaKey === true)) || 
               // Allow: home, end, left, right, down, up
              (e.keyCode &gt;= 35 &amp;&amp; e.keyCode &lt;= 40)) {
                   // let it happen, don't do anything
                   return;
          }
          // Ensure that it is a number and stop the keypress
          if ((e.shiftKey || (e.keyCode &lt; 48 || e.keyCode &gt; 57)) &amp;&amp; (e.keyCode &lt; 96 || e.keyCode &gt; 105)) {
              e.preventDefault();
          }
      });
  });
  </code></pre>
  
  <p>This works fine, except one small problem. It does not allow anything to be pasted in the field. How can I allow user to paste a string in the field, only if the string contains all numeric characters?</p>
  
  <p>Also, it will be awesome if I could do the same for input text fields allowing only alphabets.</p>