You must Sign In to post a response.
  • Category: [Competition Entries]

    I need to validate the textbox such that it can accept values only less than or equal to 1

    I need to validate the textbox such that it can accept values only less than or equal to 100.00 with Decimal.
  • #693779
    You can use the Range validator set the type as Float and Value as 100.00


    <asp:RangeValidator
    id="ProgrammaticID"
    ControlToValidate="txtVal"
    MinimumValue="0.0"
    MaximumValue="100.00"
    Type="Float"
    ErrorMessage="Error"
    Text="Please enter decimal"
    ForeColor="Red"
    BackColor="Yellow"
    runat="server" >
    </asp:RangeValidator>

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #693808
    Hi,
    Please check below code. You should add one range validator and a regular expression validator for your textbox.


    <asp:TextBox ID="txtNum" runat="server" ValidationGroup="GrpDecimal"></asp:TextBox>

    <asp:RangeValidator ID="ValRange" runat="server" ControlToValidate="txtNum"
    MaximumValue="100.00" MinimumValue="0.00" ValidationGroup="GrpDecimal"
    ErrorMessage="Enter value between 0.00 to 100.00" SetFocusOnError="True"
    Type="Double" Display="Dynamic"></asp:RangeValidator>

    <asp:RegularExpressionValidator id="regxDecimal" runat="server"
    ControlToValidate="txtNum" ValidationExpression="^\d+([\.][0-9]{0,2})?$"
    ErrorMessage="You are allowed to enter only 2 Decimal Places." ValidationGroup="GrpDecimal"/>


    Regards,
    Asheej T K

  • #693814
    tq...but sorry..i want in java script...

  • #693839
    You can do it in Javascript. check following javascript code snippet it will help you


    function validateInput()
    {
    var TextBoxVal = document.getElementById("txtValue");
    if(isNaN(TextBoxVal))
    {
    alert("Please enter only numeric values");
    return false;
    }

    if(parseFloat(TextBoxVal) > 100.00)
    {
    alert("Please enter value less than or equal to 100.00");
    return false;
    }

    }


    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.