How to valid Numeric values onkeypress
<p>I have this simple HTML document</p>

<pre><code>&lt;input type="text"  id="my_text" onkeypress="valid_numbers(event);" size="30"/&gt;
&lt;script type="javascript"&gt;
function valid_numbers(e)
{
        var key=e.which || e.KeyCode;
        if  ( key &gt;=48 &amp;&amp; key &lt;= 57)
         // to check whether pressed key is number or not 
                return true; 
         else return false;
}
&lt;/script&gt;
</code></pre>

<p><strong>What I want is:</strong></p>

<p>onkeypress of <code>my_text</code> if the pressed key is number allow otherwise deny writing of the character.</p>

<p><strong>But</strong> the above code doesn't work, <code>my_text</code> element accept any character, what is wrong with the above code ?!.. </p>

<p><strong>Help Please!..</strong> </p>