Allow Only Numbers in the Input Field

Hi folx.
I’m looking to restrict a field to numeric input.
The following neat example from w3schools shows how to achieve the exact opposite of that - blocking only numbers.

        <script type="text/javascript">
            function noNumbers(e)
                var keynum;
                var keychar;
                var numcheck;	
                if(window.event) // IE
                    keynum = e.keyCode;
                else if(e.which) // Netscape/Firefox/Opera
                    keynum = e.which;
                keychar = String.fromCharCode(keynum);
                numcheck = /\d/;
                return !numcheck.test(keychar);
            Type some text (numbers not allowed):
            <input type="text" onkeydown="return noNumbers(event)" />

I found that removing the exclamation mark (!) on line #19: ([FONT=“Courier New”]return [COLOR=“Red”]![/COLOR]numcheck.test(keychar);[/FONT]) switches it to allowing only numbers. However, as a consequence, such keys as Shift, Ctrl, Home, End, Insert, Delete, Backspace, etc are also blocked, so some of the useful functionalities, e.g. user’s ability to Shift-select are disabled.

Question: How do I modify this code so the input field would accept only numbers without compromising those basic text editing functionalities or the concise elegance of the code.
Thank you much.

PS. I never explored JavaScript before.