I am trying to restrict user's input if user is trying to type some characters (like space). To do so I found this post.
But I wanted to make it through HTML's onkeypress attribute. And faced with problem, that if I specify function to return false, then nothing will happen, but if I return false right in HTML's attribute - input won't happen.
I can't understand what am I doing wrong. Can you please tell me how to solve this?
function doMatch() {
return false;
}
$('#test').keypress(function() {
//return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" onkeypress="doMatch();" id="test"/>