Solved

Validating dates in format dd MMM yyyy

Posted on 2004-10-04
11
1,617 Views
Last Modified: 2012-06-27
I am writing an app that will be accessed by UK and US users, so date input is tricky. I decided to enforce date input in the format dd MMM yyyy (eg 05 Oct 2004) as it is unambiguous. I used a regular expression validator to check for 2 digits, a space, 3 alpha, a space, 4 digits. That bit works. But when I use a RangeValidator to check it is a valid date, so that people don't input 99 XYZ 1234, it fails even on 'valid' dates.

Any suggestions how I can handle UK and US date input?
0
Comment
Question by:crescendo
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 9

Author Comment

by:crescendo
ID: 12222268
Sorry, I meant a CompareValidator, not a RangeValidator.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 12224091
Can u add the regular expression for clarity?
0
 
LVL 8

Expert Comment

by:boulder_bum
ID: 12224321
Maybe a globalization settings issue?

If all else fails, I suppose you can use two Regex validators. Inelegant, perhaps, but it should work.
0
 
LVL 9

Author Comment

by:crescendo
ID: 12224511
I think I wasn't clear.

The RegEx works, so I can validate the general format. BUT... I still need to check that the month names and number of days in the month are valid, e.g. not allow 29 Feb 2003. I hoped the CompareValidator, set to check a date data type, would do this, but it complains because it presumably expects 30/11/2004 (UK) format dates, not 30 Nov 2004.

I can't change the regional settings because there are other webs on the server and it might affect them.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 12224550
Why dont you try writing a java script for the same to validate the dates?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Author Comment

by:crescendo
ID: 12224651
<<Why dont you try writing a java script for the same to validate the dates?>>

I was assuming that I wasn't the first person in the universe to have to accept and validate dates from both UK and US users, so there must be a solution out there which would save me doing all the work myself.

I'll write it in server-side code.

Thanks

0
 
LVL 21

Expert Comment

by:surajguptha
ID: 12224688
Just a suggestion: Why dont you use a dropdown for the months to enforce MMM or may be months and years?
0
 
LVL 9

Author Comment

by:crescendo
ID: 12224717
I'd still have the same problem of validating the number of days in each month.

I'm just surprised that the CompareValidator doesn't allow this format. Perhaps it only allows the format set on the regional settings, so if I set that it would work. But, as I said above, that would break other apps.
0
 
LVL 8

Expert Comment

by:boulder_bum
ID: 12224949
I believe you can handle the System.Globalization issues on a more local level. This may help, may not. I haven't really had to deal with this issue before.

DateTimeFormatInfo Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp

Once America takes over THE REST of the world, this won't be so much of an issue. Metric system be damned.

I wouldn't be surprised if you can tweak the culture settings for the validator.
0
 
LVL 3

Accepted Solution

by:
dabitbol earned 250 total points
ID: 12228030
I had the same problem than you and just used a calendar control. I think it's the simplest way. You can make as a pop-up calendar that inputs that date in read-only textbox.

David
0
 
LVL 3

Expert Comment

by:dabitbol
ID: 12229981
glad I could help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set cookies HttpOnly and Secure 4 107
Need an intro to -- .Net SQL Authorization Manager 7 75
Code works but how can I download the file? 20 67
LINQ - C# to VB convertion 12 45
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now