I have a textbox, and it needs not allow the user to enter any special characters. He can enter:
O
Now that we have HTML5, you don't even need to use JavaScript. You can use the pattern attribute.
The pattern attribute should contain a regular expression defining the format. And title should contain a human-readable description of the format.
Then on validation, depending on the browser, the browser will outline the field in red and/or display a message stating your description of the format.
This tutorial goes into more detail: HTML5 Input Validation Tutorial.