//金额验证
function validate(obj)
{
var regex = /^\d[\d,]*([.]\d{1,2})?$/; // 123,456.09 or 123456 or 1,23,,,45,6.09 or 123456,,,,,.09
if (obj.value != "")
{
if (!obj.value.match(regex))
{
alert('请输入正确的金额!');
obj.focus();
return;
}
}
}
<asp:TextBox ID="txtPrice" runat="server" Width="350px" MaxLength="10" onblur="validate(this)"></asp:TextBox>
---------------------------------------------------------------------------------------------------------------------
//只能输入整数
<asp:TextBox ID="txtPhoneNo" runat="server" Width="150px" MaxLength="25" onKeyup="this.value=this.value.replace(/[^0-9]/g,'');" onBlur="this.value=this.value.replace(/[^0-9]/g,'');" style="ime-mode:disabled"></asp:TextBox>
style="ime-mode:disabled" 关闭输入法
---------------------------------------------------------------------------------------------------------------------
function validate(obj)
{
var regex = /^\d[\d,]*([.]\d{1,2})?$/; // 123,456.09 or 123456 or 1,23,,,45,6.09 or 123456,,,,,.09
if (obj.value != "")
{
if (!obj.value.match(regex))
{
alert('请输入正确的金额!');
obj.focus();
return;
}
}
}
<asp:TextBox ID="txtPrice" runat="server" Width="350px" MaxLength="10" onblur="validate(this)"></asp:TextBox>
---------------------------------------------------------------------------------------------------------------------
//只能输入整数
<asp:TextBox ID="txtPhoneNo" runat="server" Width="150px" MaxLength="25" onKeyup="this.value=this.value.replace(/[^0-9]/g,'');" onBlur="this.value=this.value.replace(/[^0-9]/g,'');" style="ime-mode:disabled"></asp:TextBox>
style="ime-mode:disabled" 关闭输入法
---------------------------------------------------------------------------------------------------------------------
浙公网安备 33010602011771号