Validate Required NumericTextBox Type Set to Currency

4 posts, 1 answers
  1. Fred
    Fred avatar
    86 posts
    Member since:
    Sep 2008

    Posted 10 Jun 2009 Link to this post

    I'm sure I'm missing something small here.  I wanted to do a "RequiredFieldValidator" on a RADNumericTextBox with the Type=Currency and it's mask is $0.00

    Seems that .Net's validator doesn't show the field as empty with the mask in it. 

    Any thoughts?

    How to force a NumericTextBox set to Currency with a mask, to not accept $0.00 ( 0 ) as the value.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Jun 2009 Link to this post

    Hi Fred,

    Try the following approach by setting the InitiaValue for RequiredFiieldValidator to 0. Here is my code.

    ASPX:
     
    <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Type="Currency" Value="0">  
    </telerik:RadNumericTextBox> 
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="RadNumericTextBox1" ErrorMessage="Enter valid amount" InitialValue="0">  
    </asp:RequiredFieldValidator><br /> 
    <br /> 
    <asp:Button ID="Button1" runat="server" Text="Submit" /> 

    Thanks,
    Princy.
  3. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 11 Jun 2009 Link to this post

    Hello Fred,

    If I understand your requirements correctly you have two options:
     - using RequiredFieldValidator
        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" 
            ControlToValidate="Numeric" Text="Error" InitialValue="0">  
        </asp:RequiredFieldValidator> 

    - using CustomValidator
    <asp:CustomValidator runat="server" ID="CustomValidator1"   
      ControlToValidate="Numeric" Text="Error" ValidateEmptyText="true" 
      ClientValidationFunction="clientValidationFunciton">  
    </asp:CustomValidator> 

    with client validation function:
    function clientValidationFunciton(sender, args)  
    {              
      if (args.Value === "" || parseInt(args.Value, 10) == 0)  
        args.IsValid = false;  


    Greetings,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. Fred
    Fred avatar
    86 posts
    Member since:
    Sep 2008

    Posted 11 Jun 2009 Link to this post

    Thanks!! Totally forgot about InitialValue, doh!! works like a charm.
Back to Top