在文本框中设置的值不超过小数点后 2 位



>我有一个文本框,允许用户用十进制值键入值。如何在文本框中设置只能输入2位小数。现在,用户可以键入超过2个小数位。下面是文本框的代码:

<td><b>Payment Amount:</b></td>
                            <td colspan="2">
                                <asp:TextBox ID="txtPayment" runat="server" Enabled="true" CssClass="form-control"/>
                                <asp:RequiredFieldValidator ID="rfvPayment" runat="server" ControlToValidate="txtPayment" ValidationGroup="SubmitGroup" Display="Dynamic" ErrorMessage="* Please fill in this section" />
                                <asp:RangeValidator ID="rgPayment" runat="server" ControlToValidate="txtPayment" Display="Dynamic" Type="Double"/>
                            </td>

对于文本框,在id=rgPayment上,我使用范围验证器来验证值。这里的代码:

protected void lnkbtnB2CProceed_Click(object sender, EventArgs e)
    {
        rgPayment.MaximumValue = "30000";
        rgPayment.MinimumValue = "1";
        txtPayVia.Text = "Retail Banking";
        if (CheckAmount())
        {
            Proceed(Resources.Default.FPXMsgTokenB2C);
            trSupportedChannel.Visible = false;
        }
    }
    protected void lnkbtnB2BProceed_Click(object sender, EventArgs e)
    {
        rgPayment.MaximumValue = "1000000";
        rgPayment.MinimumValue = "2";
        txtPayVia.Text = "Corporate Banking (FPX)";
        if (CheckAmount())
        {
            Proceed(Resources.Default.FPXMsgTokenB2B);
            trSupportedChannel.Visible = false;
        }
    }

谢谢

您可以下载 JQuery 数字掩码插件并将其添加到您的页面上。然后使用

$('[id*="txtPayment"]').numeric({ decimal : ".",  negative : false, scale: 2 });

最新更新