Discussions Search    Reviews    Search Aid    Buzzzz    Google@Omgili Add to iGoogle   Bookmark and Share

  Advanced Search



date validation

On Thu, 03 Jul 2008 11:37:08 +0200, maz77 <...@nospam.com

I'm trying to develop a good validation for a date in C#; a valid date
can be inserted in these formats:
- dd/mm/yyyy
- dd/mm/yyyy h24:m
- mm/dd/yyyy
- mm/dd/yyyy h12:m
How can I proceed?
Is "Datetime.TryParse()" a good choice?

Thanks

MAX

 Latest discussions from this group  (microsoft.public.dotnet.framework.aspnet)

How do I have SiteMap based on output of stored procedure?  
[28 Aug 2008]
On Thu, 28 Aug 2008 11:22:05 +1200, "Mark B" <none123@none.com How do I have a SiteMap...
based on the output of a stored procedure? (I want to pass a @LanguageCode parameter to...
Substitute sitemap node titles on-the-fly?  
[28 Aug 2008]
On Thu, 28 Aug 2008 10:51:02 +1200, "Mark B" <none123@none.com My ASP.NET 3.5 Menu Control...
uses a Sitemap. How can I change certain menu titles/URL's programmatically on-the-...
Implement Web Application as httpModule?  
[27 Aug 2008]
On Wed, 27 Aug 2008 18:15:36 -0400, "Joseph Geretz" <jgeretz@nospam.c om I'm implementing...
a web application whose purpose in life is to act as a data conduit. Data is posted to...
More...


On Thu, 3 Jul 2008 02:44:33 -0700 (PDT), Munna <...@gmail.com

Hi

Is "Datetime.TryParse()" a good choice?

yes it is

Best of luck

Munna

http://www.munna.shatkotha.com/blog
http://www.munna.shatkotha.com
http://www.shatkotha.com

On Thu, 3 Jul 2008 11:43:02 +0100, "Mark Rae [MVP]" <...@markNOSPAMrae.net

"maz77" <...@reader2.news.tin.it...


Yes it is.

However, you've posted your question on an ASP.NET newsgroup, so I'm
assuming that you intend to use this in an ASP.NET app...

There is, generally speaking, no need to use server-side validation for data
entry as this can be just as easily accomplished client-side - the obvious
exception to this is when data needs to be validated against server-side
resources e.g. a database etc... Reducing the amount of roundtrips to the
server and back is always a good thing, IMO...

ASP.NET has its own validation controls which can be configured to validate
several types of data, including dates:
http://msdn.microsoft.com/en-us/library/debza5t0.aspx

Personally, I never go anywhere near those because I find them too
restrictive - some people absolutely love them...

I have my own suite of client-side JavaScript data validation routines,
including many which relate to dates.

However, my preferred method is to use a calendar control and not permit
users to enter date values by typing, thereby making the whole exercise of
data format validation unnecessary...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

On Thu, 3 Jul 2008 15:31:05 +0100, "Andrew Morton" <...@in-press.co.uk.invalid


Surely you should mention the caveat about protecting against malicious
users who might bypass the client-side validation for the purposes of SQL
injection, XSS, or just plain invalid data?

Andrew


On Thu, 3 Jul 2008 16:02:17 +0100, "Mark Rae [MVP]" <...@markNOSPAMrae.net

"Andrew Morton" <...@mid.individual.net...


SQL Injection is fairly simply bypassed by using stored procedures and / or
parameterised queries.

As for invalid dates specifically, they can be avoided completely by using a
calendar control, the premise being that if users can't actually type a date
into a field they can't type an invalid date into a field...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

On Thu, 3 Jul 2008 17:07:58 +0100, "Andrew Morton" <...@in-press.co.uk.invalid


I was writing about malicious users in particular, who will have
tools/browser add-ons to alter the data en route from the browser to the
server or enter data directly into hidden fields - or does ASP.NET validate
the raw data in some way?

Andrew


Discussion Title: date validation
Title Keywords: date  validation