Yet more DATE validation problems (C#)

P

Pete

Specifically, I want to force the user to enter date in a textbox as a
4 digit year so that I don't have to figure out what century they
intend. Also, I don't want to deal with date range assumptions that 2
digit year begets.

My expectation is that I can use a compareValidator, set the type to
date, then supply the format criteria as a string in ValueToCompare:
mm/dd/yyyy. After studying the newsgroups, I don't see that option
using the CompareValidator alone. I see no example of what
ValueToCompare should be if Type is Date, either. The string mnemonic
(mm/dd/yyyy, or variations) causes rendering error.

I have attempted to use the recommendation of Peter Blum:

System.Globalization.CultureInfo vCulture =
(System.Globalization.CultureInfo)
System.Globalization.CultureInfo.CreateSpecificCulture("en-US").Clone();
vCulture.DateTimeFormat.ShortDatePattern = "mm/dd/yyyy";
System.Threading.Thread.CurrentThread.CurrentUICulture = vCulture;

without success -- I can still enter a 2 digit year without getting a
validation error. I put the above in the Page_Load method of the
textbox page as prescribed. What else can I do?

It boggles the mind that one of the most common data entry problems,
dates, is so poorly documented (meaning precious few examples) and
implemented in VS 2003 -- or ASP.NET, whichever is at fault.
 
P

Pete

Steve,

Thank you for replying.

Are you saying that I should add another validator - a regex validator
- that looks at mm/dd/yyyy and pipe that to the CompareValidator to
make sure it's a date?

Can you show me how this is done, or is it automatic?
 
S

Steve C. Orr [MVP, MCSD]

From the information you've provided, I don't see why a Comparevalidator
would be necessary at all.
If you want to validate a properly formatted date has been entered, then you
use the RegularExpressionValidator.
If you want to compare the date to some other value somewhere then you could
use the CompareValidator in addition to the RegularExpressionValidator.
 
P

Pete

Thank you again, Steve, for replying.

According to Peter Blum, a regular expression validator should not be
used because it doesn't validate type Date. IOW, I must know that what
is entered is a valid date along with making sure that it is 4 digit
year. I want it done on the Client side via the validators (if I
understand it right) so that the server isn't burdened with inspecting
the user data and then sending back some error message. Are you saying
a regular expression does this? What I desperately need is a working
example. This must be a very common problem. Didn't Y2K cause this to
be a prominent issue?

I need to see how the properties are filled in. What specifically would
be typed. Without an example I have no way to know because it isn't
scientific theory, it's convention. The documentation does little to
expose the details.
 
S

Steve C. Orr [MVP, MCSD]

Oh, now I see. The RegularExpressionValidator doesn't come with a built in
date regular expression for you to easily use.
But don't let that stop you.
Make your own regular expression, or find a pre-made one on
www.regexplib.com
 
P

Pete

Steve,

Again, thank you for replying. Not sure, but it seems like you're being
a little bit snide..."Oh, now I see. The RegularExpressionValidator
doesn't come with a built in date regular expression for you to easily
use. "

My issue is that regular expressions don't know about leap years, and
don't know that months don't all have 31 days, etc.

Furthermore, it just shouldn't be this difficult to do something so
bloody simple as force 4 digit year date entry.

But, thanks for the edit mask link - will be handy for social security
number and telephone number.

Think I'll convert the project to Delphi as a final solution.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top