You must Sign In to post a response.
  • Category: ASP.NET

    Range validator not working with decimal value with comma

    Hello.
    I have below code in asp.net with textbox.
    If I put value in textbox with decimal and comma like, "1,000.00".
    In range validator, I have given min value 0 and max 2000.
    Here, value inserted should allow but because of comma, it always give validation that out of range. How to solve this.

    <asp:TextBox runat="server" ID="txtAmounts" Width="95px" MaxLength="10" AutoPostBack="false"
    OnTextChanged="txtAmounts_TextChanged" onkeydown="return (event.keyCode!=13);"
    Enabled='<% #Eval("MakeBasicEditable")%>' Text='<%#Eval("salarygivenamount") %>'
    Style="text-align: right;"></asp:TextBox>

    <asp:FilteredTextBoxExtender runat="server" ID="ftbextamounts" TargetControlID="txtAmounts"
    FilterType="Custom" ValidChars="1234567809.,">
    </asp:FilteredTextBoxExtender>

    <asp:RangeValidator runat="server" ID="rangvalAmount" ControlToValidate="txtAmounts"
    Type="Double" MinimumValue='<% #Eval("Minamount")%>' MaximumValue='<% #Eval("Maxamount")%>'
    ErrorMessage="Amount is not in valid range" Display="None" ValidationGroup="SaveTransfer"
    Enabled='<% #Eval("ShowRangeValidator")%>'></asp:RangeValidator>
  • #768785
    Hi,



    <asp:TextBox runat="server" ID="txtAmounts" Width="95px" MaxLength="10" AutoPostBack="false"
    OnTextChanged="txtAmounts_TextChanged" onkeydown="return (event.keyCode!=13);"
    Enabled='<% #Eval("MakeBasicEditable")%>' Text='<%#Eval("salarygivenamount") %>'
    Style="text-align: right;"></asp:TextBox>

    <asp:RegularExpressionValidator ID="reValidator" runat="server"
    ControlToValidate="TextBox1"
    EnableClientScript="True"
    ErrorMessage="Invalid Format!"
    Display="Dynamic"
    ValidationExpression="(\d{1,3}(,\d{3})*\.\d{2})|(\d+(\.\d{2})?)" />


    Can you add this regularExpression validator below the textbox command and check once.

    Thanks,
    Mani


  • Sign In to post your comments