472,336 Members | 1,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,336 software developers and data experts.

date validation

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
5 1983
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
"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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are...
0
by: Brian Conway | last post by:
I am having some validation and insertion problems. I am using a date picker that takes the selected date and puts it to ("dd-MMM-yyyy") format,...
7
by: Paul | last post by:
Hi, I have a form where a user is required to enter a start date and an end date. Both are required and must between a specific date range (e.g....
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make...
12
by: Diego | last post by:
Can I validate (possibly with a compare validator) a Date entered by the user based upon his regional settings? I.e. if a user is american the...
1
by: Brendan Reynolds | last post by:
In an ASP.NET 1.1 app I have the following range validation control. This is an intranet app that will be used only within Ireland, so all date...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this...
3
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I have VS 2005 (C#) There is a control numericUpDown so you can spin numeric values. What I need to do is to spin date (+- one day). How to do...
2
by: John Smith | last post by:
Hello, I have a VB.NET application with a Windows form that have several textboxes fields where I have dates entered. I would like to do a date...
5
Stang02GT
by: Stang02GT | last post by:
I have been asked to validate a date on our web-page so that people cannot enter dates like 14/1/08 or 2/30/06. I have found code that will do...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.