MrDave's (David Yack) WebLog

Date Validation

Only advice I can pass along is avoid doing complex regular expressions early on Monday mornings!

It would sure be nice if MS would include a Date Validator or add that as an option to the Regular Expression Validation in Whidbey.

In case you don't know about the great resource for regular expressions here's a link:

http://www.regexlib.com

Comments

Phil Scott said:

What about using a compare validator against the date type?
# January 12, 2004 10:57 AM

Jeff Schoolcraft said:

What about: http://regexblogs.com/jschoolcraft/archive/2003/11/11/155.aspx

It's not a full validator, but you could use that function in a custom validator...
# January 12, 2004 11:31 AM

AndrewSeven said:

Annother good regex site.
http://www.regular-expressions.info

I've used the compare validator without too much difficulty.

# January 12, 2004 12:47 PM

Josh said:

I'm pretty sure the "Date mode" of the compare validator is not culture aware. It may not matter to you, but it is pretty shocking to me considering how much attention the .NET team payed to making everything culture aware.
# January 12, 2004 4:42 PM

Shannon said:

What about the range validator?
# January 12, 2004 6:04 PM

Paul Reynolds said:

The compare validator outputs an attribute called dateorder which defaults to mdy. However, you cannot access this through server code to change to dmy...if you try calling AddAttributes, you end up with two entries...even when you try creating your own derived class, there is a function that returns the dateorder as a string, but nothing to set it.
# April 19, 2004 12:01 AM

Ryan Haney said:

The compare validator format is based on the current culture (I am using ASP.NET 2.0).  This is why you cannot change it.  The issue then becomes where do you translate the date back to the culture your database is expecting (i.e. en-US).  I would say the best place would be a method off a custom composite control called DateTextBox called TranslateToCulture(string culture).  The method would take a culture, and if it is different than the current, attempt to translate it.  Otherwise it would just pass back the current value for the control.

# July 14, 2007 2:31 PM

amol kinge said:

very nice also i want to validate date within 7 days from todays date if any body knows let me know

# January 29, 2008 5:00 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)