This is a migrated thread and some comments may be shown as answers.

Validate Required NumericTextBox Type Set to Currency

3 Answers 162 Views
Input
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 10 Jun 2009, 03:12 PM
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.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Jun 2009, 08:01 AM
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.
0
Accepted
Nikolay Rusev
Telerik team
answered on 11 Jun 2009, 08:03 AM
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.
0
Fred
Top achievements
Rank 1
answered on 11 Jun 2009, 01:54 PM
Thanks!! Totally forgot about InitialValue, doh!! works like a charm.
Tags
Input
Asked by
Fred
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Nikolay Rusev
Telerik team
Fred
Top achievements
Rank 1
Share this question
or