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

RadDateInput - time input validation issue

1 Answer 75 Views
Input
This is a migrated thread and some comments may be shown as answers.
Steve LaForge
Top achievements
Rank 1
Steve LaForge asked on 26 Oct 2010, 08:19 PM
I am trying to validate the input of a military time.  However, it always rejects whatever I enter for the time in the RadDateInput field, but the validation works just fine in a textbox.  My test code looks like:

Time: 
  <telerik:RadDateInput ID="RadDateInput1" runat="server" DateFormat="HH:mm" Width="50" /> 
  <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
    ErrorMessage="Invalid Time" ControlToValidate="RadDateInput1" Display="Dynamic" 
    ValidationExpression="(([01][0-9])|(2[0-3])):[0-5][0-9]" SetFocusOnError="true" /> 
  <br /> 
Time2: 
  <asp:TextBox ID="txtTime" runat="server" Width="50" />     
  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
    ErrorMessage="Invalid Time2" ControlToValidate="txtTime" Display="Dynamic" 
    ValidationExpression="(([01][0-9])|(2[0-3])):[0-5][0-9]" SetFocusOnError="true" /> 
  <br />
<asp:Button ID="btnSubmit" runat="server" CausesValidation="true" Text="Submit" />

Can someone please tell me what I am doing wrong?

Many thanks!

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 28 Oct 2010, 09:27 AM
Hi Steve,

The RadDateInput works with Javascript Date objects client-side, regardless of the DateFormat. The control stores its value in a hidden textbox in the following culture independent format:

2010-10-28-11-00-00

yyyy-MM-dd-HH-mm-ss

The hidden texbox is the actual control, because its ID matches the RadDateInput's ClientID. The visible textbox has a different ID. So the validators work with the hidden textbox. If the control holds an invalid value, the hidden textbox is empty and the validator will receive an empty string as a value. If the control holds a valid value, the validator will receive a value in the above format. So actually you don't have to use a RegularExpressionValidator with RadDateInput in your case - you can either use a RequiredFieldValidator, or a CustomValidator.

Regards,
Dimo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Input
Asked by
Steve LaForge
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or