I also have a date picker to have user select date in mm/dd/yyyy format, which gets written to the text box my validation is assigned.
The problem I've been trying to solve is when the date comes back from the database (which is stored as datetime), a date like 07/09/2008 displays as 7/9/2008. When a user tries to update a different field on the same screen,
my validation expression for the date kicks in because of the 7/9/2008, which it expects to be 07/09/2008.
My question is what would be the best plan to fix this, change the validation expression or the display? I've been trying to change the regular validation expression, with no luck. I finally got a date picker working this
morning, after several days trying things for that. Now I'm stuck on this particular issue with validation.
Here is the regex that I use when validating dates, it matches the dates per month and checks for leap years, it should also fix your problem with the 0 in front of the day and month, right now it does not allow for a year before 1900 but can be easily modified
to do so.
¤´¨)
¸.•´ ¸.•*´¨) ¸.•
(¸¸.•´ .•If you find my post helpful, please mark it.
Thanks! (¸¸.•´ ¸.•
(¸.¤
joezimo
Member
221 Points
54 Posts
date validation for mm/dd/yyyy
Jul 16, 2008 04:03 PM|LINK
ValidationExpression
="(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d">I also have a date picker to have user select date in mm/dd/yyyy format, which gets written to the text box my validation is assigned.
The problem I've been trying to solve is when the date comes back from the database (which is stored as datetime), a date like 07/09/2008 displays as 7/9/2008. When a user tries to update a different field on the same screen, my validation expression for the date kicks in because of the 7/9/2008, which it expects to be 07/09/2008.
My question is what would be the best plan to fix this, change the validation expression or the display? I've been trying to change the regular validation expression, with no luck. I finally got a date picker working this morning, after several days trying things for that. Now I'm stuck on this particular issue with validation.
Thanks in advance.
SGWellens
All-Star
126031 Points
10310 Posts
Moderator
Re: date validation for mm/dd/yyyy
Jul 16, 2008 04:07 PM|LINK
When the date comes from the database, format it to match the regular expression. MM/dd/yyyy
My blog
joezimo
Member
221 Points
54 Posts
Re: date validation for mm/dd/yyyy
Jul 16, 2008 04:12 PM|LINK
Thanks, When I tried the following, it does not seem to work:
Text='<%# Bind("financial_statement_date", "{0:mm/dd/yyyy}")
Still comes back from the database as 7/9/2008, not 07/09/2008.
TonyG_
Member
388 Points
68 Posts
Re: date validation for mm/dd/yyyy
Jul 16, 2008 04:21 PM|LINK
(((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)))
Here is the regex that I use when validating dates, it matches the dates per month and checks for leap years, it should also fix your problem with the 0 in front of the day and month, right now it does not allow for a year before 1900 but can be easily modified to do so.
¸.•´ ¸.•*´¨) ¸.•
(¸¸.•´ .•If you find my post helpful, please mark it.
Thanks! (¸¸.•´ ¸.•
(¸.¤
HeartattacK
All-Star
55262 Points
5917 Posts
Moderator
MVP
Re: date validation for mm/dd/yyyy
Jul 16, 2008 04:25 PM|LINK
<%# Bind("dateCreated", "{0:MM/dd/yyyy}") %>
Small m is for minutes.
blog: www.heartysoft.com
twitter: @ashic
joezimo
Member
221 Points
54 Posts
Re: date validation for mm/dd/yyyy
Jul 16, 2008 04:31 PM|LINK
Thanks Heartattack, that was my problem all along. I think Steve was telling me this right off the bat. Thanks again.
Joe