By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

date validation

P: n/a
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
Jul 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi

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

yes it is

Best of luck

Munna

www.munna.shatkotha.com/blog
www.munna.shatkotha.com
www.shatkotha.com
Jul 3 '08 #2

P: n/a
"maz77" <no****@nospam.comwrote in message
news:48***********************@reader2.news.tin.it ...
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?
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

Jul 3 '08 #3

P: n/a
Mark Rae [MVP] wrote:
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...
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
Jul 3 '08 #4

P: n/a
"Andrew Morton" <ak*@in-press.co.uk.invalidwrote in message
news:6d***********@mid.individual.net...
Mark Rae [MVP] wrote:
>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...

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?
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

Jul 3 '08 #5

P: n/a
Mark Rae [MVP] wrote:
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...
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
Jul 3 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.