你可以把正则表达式写在 onkeyup 事件里呀. 比如说只能输入数字的文本框:
<input onkeyup="this.value=this.value.replace(/\D/g, '')">