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

using asp.net regular expression validation on a raddatetimepicker

3 Answers 353 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 03 Oct 2008, 11:36 PM
Hello,

I have a question 

Similar to this thread: http://www.telerik.com/community/forums/thread/b311D-mebde.aspx

I would like to use the normal ASP.net validation controls with the RadDatePicker and perform client-side validation
rather than the inbuilt validation of the RadDatePicker. 
I do not want the RadDatePicker style to change when an invalid date is entered.

when I'm validating against the normal text box, I use a regular expression validator, and then display a message next to the text box with the correct date format.
This is how I validate all the rest of the controls in the web site, and I want to maintain consistency of look and feel of the validation

when I try and use a regular expression validator against the RadDatePicker, the validation fails.

How can I correctly hook up a client-side regular expression validator to a RadDatePicker?

Can I disable the RadDatePicker validation functionality?

If I can't disable the RadDatePicker validation functionality, I imagine that I would need to change the skin for the control.  Is this correct?

Basically what I'm looking for is a regular text box that is hooked up to a calendar automatically, rather than having to code a rad window with an embedded calendar.

This is my code, the textbooks validation works, the RadDatePicker validation does not

<td noWrap align=right >Reminder Date:</td>

<td >

<table>

<tr>

<td><asp:TextBox ID="txtReminderDate" runat="server" Enabled="false"></asp:TextBox></td>

<td><asp:RequiredFieldValidator ID="reqvalReminderDate" runat="server" Enabled="false" ErrorMessage="Reminder Date is required." ControlToValidate="txtReminderDate">*</asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="regvalReminderDate" runat="server" ErrorMessage="Reminder Date is invalid" Enabled=false ValidationExpression="(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))" ControlToValidate="txtReminderDate">* mm/dd/yyyy</asp:RegularExpressionValidator></td>

</tr>

</table>

</td>

</tr>

<tr>

<td noWrap align=right >Reminder Date:</td>

<td >

<table>

<tr>

<td><telerik:RadDatePicker ID="rdpReminderDate" Runat="server" enabled="false"

Culture="English (United States)" Skin="Default2006">

<DateInput DateFormat="MM/dd/yyyy" LabelCssClass="radLabelCss_Default2006"

Skin="Default2006">

</DateInput>

<

Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x"

Skin="Default2006"></Calendar>

</telerik:RadDatePicker></td>

<td><asp:RequiredFieldValidator ID="reqvalReminderDateRDP" runat="server" Enabled="false" ErrorMessage="Reminder Date is required." ControlToValidate="rdpReminderDate">*</asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="regvalReminderDateRDP" runat="server" ErrorMessage="Reminder Date is invalid" Enabled=false ValidationExpression="(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))" ControlToValidate="rdpReminderDate">* mm/dd/yyyy</asp:RegularExpressionValidator>

</td>

</tr>

Thanks
Jonathan

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 06 Oct 2008, 12:14 PM
Hello Jonathan,

Currently there is no option for  disabling the inbuilt RadDatePicker validation. Could you please elaborate a little bit more what is the RegularExpression validation used for in your page, If you need to allow only particular date formats to be added in the DatePicker control you could use the RadDatePicker.DateFormat property and still use the activated inbuild validation. Please review the following help topic for more information on this property.

Sincerely yours,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Martin Sarosi
Top achievements
Rank 2
answered on 15 Feb 2011, 06:13 PM
This doesn't prevent a postback when a button is clicked though!
0
Maria Ilieva
Telerik team
answered on 18 Feb 2011, 12:49 PM
Hi Martin,

You are correct that on this case the postback will not be prevented but to input will automatically correct to the correct format. Another suggestion could be to replace the DateInput component of datepicker with regular asp:textbox and validate the textbox value per your needs.
I hope this covers your requirements.


Best wishes,
Maria Ilieva
the Telerik team

Tags
Calendar
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Martin Sarosi
Top achievements
Rank 2
Share this question
or