Text input numerical validation
<p>I'm trying to have a textfield only allow numbers. (i.e. "0-9" not decimals.) I came upon <a href="https://stackoverflow.com/a/469362/4861207">this popular answer</a> which said to do:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input type="text" onkeypress='return event.charCode &gt;= 48 &amp;&amp; event.charCode &lt;= 57'&gt;&lt;/input&gt;</code></pre>
</div>
</div>
</p>

<p>I tried that, but the problem is, it allows you to paste any character in. How can I disallow pasted 'illegal' characters? Also, will this code work with different keyboards such as German keyboards?</p>

<p><strong>Please don't post about <code>type="number"</code>. I'm not using that for many reasons.</strong></p>