There is several key event that can be handled for user input controlling.
for simplification I will only talk about onkeypress
to process a user input you must have to return true or false.
as example
<input type=text onkeypress='return false;'> <!--
<input type=text onkeypress='return false;'> <!--
try this on browser.
say you want to allow only 0 and 1. the simple example would be
<script>
function test(e){
var e=window.event || e
return e.charCode==48 || e.charCode==49 ? true:false;
}
</script>
<input type=text onkeypress='return test(event);'> <!--
hope it will guide you a little