how we can restrict a character to type in a text box.
Ben Rowe's answer is indeed the way to approach it. However, the character will appear in the textbox before it is being removed. You can prevent that by using oninput instead of onkeyup:
oninput
onkeyup