1.只能輸入數字(不能輸入小數點)
<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
2.只能輸入數字(能輸入小數點)
<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
<input name=txt1 onchange="if(/\D/.test(this.value)){alert('只能輸入數字');this.value='';}">
3.只能輸入英文字母和數字,不能輸入中文
<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
4.只能輸入數字和英文
<input onKeyUp="value=value.replace(/[^\d|chun]/g,'')">