js:
<script type="text/javascript" language="javascript"> //只能输入数字 function ValidateNumber(e, pnumber) { if (!/^\d+$/.test(pnumber)) { var newValue = /^\d+/.exec(e.value); if (newValue != null) { e.value = newValue; } else { e.value = ""; } } return false; } //可以输入带小数点的数字 function ValidateFloat(e, pnumber) { if (!/^\d+[.]?\d*$/.test(pnumber)) { var newValue = /^\d+[.]?\d*/.exec(e.value); if (newValue != null) { e.value = newValue; } else { e.value = ""; } } return false; } //只可以输入一位小数点数字 function ValidateFloat2(e, pnumber) { if (!/^\d+[.]?[1-9]?$/.test(pnumber)) { var newValue = /\d+[.]?[1-9]?/.exec(e.value); if (newValue != null) { e.value = newValue; } else { e.value = ""; } } return false; } </script>
<input runat="server" id="t1" type="text" style="width: 30px" onkeydown="if(event.keyCode==13)event.keyCode=9" onkeypress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false" onkeyup="return ValidateFloat(this,value)" />
即可