Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2009, 06:08 PM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default 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
The Following User Says Thank You to SouthendSupporter For This Useful Post:
Banishah (August 4th, 2009)
 
Old August 3rd, 2009, 07:53 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Try

{0:dd/MM/yyyy}

instead of {0: dd/MM/yyyy}
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
SouthendSupporter (August 4th, 2009)
 
Old August 4th, 2009, 03:00 PM
Authorized User
 
Join Date: Jul 2009
Posts: 61
Thanks: 15
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by Lee Dumond View Post
Try

{0:dd/MM/yyyy}

instead of {0: dd/MM/yyyy}
Could have sworn I had tried that. Obviously not as I tried again and it works. Obvious really
__________________
Geoff Baldwin
 
Old August 5th, 2009, 02:46 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Things like that happen sometimes!
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I keep leading and trailing whitespaces? 2BOrNot2B XSLT 2 October 31st, 2008 11:35 AM
Removing leading zeros from a string value vikkiefd XSLT 2 June 12th, 2008 03:30 AM
Remove Leading and Trailing Zeros lene_wee SQL Server 2000 3 April 1st, 2008 08:23 AM
Leading and Kerning of Text vijay.bhaskar General .NET 0 September 26th, 2007 12:06 AM
Displaying leading whitespace djmarquette XSLT 2 January 26th, 2005 10:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.