只可以输入整数(推荐)
<script language="javascript" type="text/javascript">
function onlyNum() {
if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
event.returnValue = false;
}
</script>
<asp:TextBox ID="TextBox1" runat="server" onkeydown="onlyNum()"></asp:TextBox>
只可以输入数字与小数点(并最多可以输入两位小数)
<asp:TextBox ID="txtLossSum" runat="server" CssClass="txt" Text="0" onblur="LossSum()" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"></asp:TextBox>
<script type="text/javascript">
function LossSum() {
var d = document.getElementById("<%=txtLossSum.ClientID%>").value;
var patrn = /^\d{0,16}(\.\d{1,2})?$/; //\d{0,16}最少输入0位数,最多输入16位数;
if (!patrn.test(d)) {
alert("请输入正确的赔付金额");
return false;
}
else if (d.length > 1 && d.indexOf('0') == "0" && d.indexOf('.') != "1")
{
alert("请输入正确的赔付金额");
return false;
}
else
return true;
}
</script>