1.文本框只能输入数字(小数点也不能输入)
<input name="txt1" οnkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g, '')">
2.只能输入数字,能输小数点.
<input name="txt1" οnkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
3.只能输入数字字母下划线
<input name="txt1" onpropertychange="javascript:if(this.value!=this.value.replace(/\W/g,''))this.value=this.value.replace(/\W/g,'')" />
转载于:https://www.cnblogs.com/Cynosure/archive/2011/12/31/2308554.html