Question: for example, I want the textfield input number only. my idea is when the user typing, it will call a javascript to check whether it is valid, if it is not valid, I delete the text which is just entered. But I think it is very complex to do so. Is there any simple way to do so?

Answer: 
Put a validation on submit.
The script to do this is here. It's a pretty common requirement.

<http://javascript.internet.com/forms/validate-numeric-only.html>