Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 3rd, 2009, 06:08 PM
Authorized User
 
Join Date: Jul 2009
Location: Haslemere, Surrey, England
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)
  #2 (permalink)  
Old August 3rd, 2009, 07:53 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
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)
  #3 (permalink)  
Old August 4th, 2009, 03:00 PM
Authorized User
 
Join Date: Jul 2009
Location: Haslemere, Surrey, England
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
  #4 (permalink)  
Old August 5th, 2009, 02:46 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
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(); 
}
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.