That's good you mention Javascript. It's the best to do it on the client side, as the events you have to consume are too frequent.
Here is how:
<html>
<head>
<script type="text/javascript"><!--
function filterDigits(eventInstance) {
eventInstance = eventInstance || window.event;
key = eventInstance.keyCode || eventInstance.which;
if ((47 < key) && (key < 58) || key = 45 || key == 8) {
return true;
} else {
if (eventInstance.preventDefault) eventInstance.preventDefault();
eventInstance.returnValue = false;
return false;
}
}
--></script>
</head>
<body">
<input type="text" onkeypress="filterDigits(event)"/>
</body>
</html>
Pay attention that backspace is also allowed. By some historical reasons backspace is considered a character and should be allowed anyway.
—SA