Date displayed with leading space leading to validation rejection
I am using a details view to add and update records in a database table for events.
The event date is defined in the table as a datetime field.
The details view contains :
[code]
<asp:TemplateField HeaderText="Date" SortExpression="EventDate" ItemStyle-HorizontalAlign="Left">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("EventDate","{0: dd/MM/yyyy}") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqDate0" ControlToValidate="Textbox3" runat="server" ErrorMessage="Please enter a date for the event dd/mm/yyyy" Text="*"/>
<asp:RegularExpressionValidator ID="revDate1" runat="server" ErrorMessage="Please Enter a Valid date - dd/mm/yyyy" Text="*" ValidationExpression="^(?:(?:0?[1-9]|1\d|2[0-8])(\/|-)(?:0?[1-9]|1[0-2]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:31(\/|-)(?:0?[13578]|1[02]))|(?:(?:29|30)(\/|-)(?:0?[1,3-9]|1[0-2])))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(29(\/|-)0?2)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$" ControlToValidate="Textbox3"></asp:RegularExpressionValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("EventDate","{0: dd/mm/yyyy}") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="reqDate" ControlToValidate="Textbox3" runat="server" ErrorMessage="Please enter a date for the event dd/mm/yyyy" Text="*"/>
<asp:RegularExpressionValidator ID="revDate2" runat="server" ErrorMessage="Please Enter a Valid date - dd/mm/yyyy" Text="*" ValidationExpression="^(?:(?:0?[1-9]|1\d|2[0-8])(\/|-)(?:0?[1-9]|1[0-2]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:31(\/|-)(?:0?[13578]|1[02]))|(?:(?:29|30)(\/|-)(?:0?[1,3-9]|1[0-2])))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(29(\/|-)0?2)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$" ControlToValidate="Textbox3"></asp:RegularExpressionValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("EventDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
[\code]
Inserting a record works fine with the date being correctly validated
(as an aside anyone know of a regular expression that will allow 23 aug 2009 as well as 23/08/2009 ?)
When I display the record in edit mode the date is displayed with a leading space which causes it to be rejected as invalid when I update the record.
__________________
Geoff Baldwin
|