title: How to prevent special characters copy paste on number field
body: <p>I want to copy paste only numbers in 'number field'. If I didn't prevent copy paste I can copy the <code>'e','+','-'</code> and <code>'.'</code> in the number field. In the number field, I can type those characters so I have used another script. I want to type and copy paste only numbers.</p>
  
  <p>Please check the code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>jQuery("#otp_number").bind("cut copy paste", function(e) {
    e.preventDefault(); //prevent the default behaviour 
  });
  document.querySelector("#otp_number").addEventListener("keypress", function(evt) {
    if (evt.which != 8 &amp;&amp; evt.which != 0 &amp;&amp; evt.which &lt; 48 || evt.which &gt; 57) {
      evt.preventDefault();
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  OTP: &lt;input type="number" id="otp_number" data-ignorepaste="" /&gt;</code></pre>
  </div>
  </div>
  </p>