Yet more DATE validation problems (C#)

Discussion in 'ASP .Net Web Controls' started by Pete, Feb 10, 2005.

  1. Pete

    Pete Guest

    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.
     
    Pete, Feb 10, 2005
    #1
    1. Advertising

  2. Doesn't the regular expression validator control meet your needs?

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net



    "Pete" <> wrote in message
    news:...
    > 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.
    >
     
    Steve C. Orr [MVP, MCSD], Feb 10, 2005
    #2
    1. Advertising

  3. Pete

    Pete Guest

    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?


    Steve C. Orr [MVP, MCSD] wrote:
    > Doesn't the regular expression validator control meet your needs?
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD, MVP
    > http://SteveOrr.net
    >
    >
     
    Pete, Feb 11, 2005
    #3
  4. 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.

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "Pete" <> wrote in message
    news:...
    > 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?
    >
    >
    > Steve C. Orr [MVP, MCSD] wrote:
    >> Doesn't the regular expression validator control meet your needs?
    >>
    >> --
    >> I hope this helps,
    >> Steve C. Orr, MCSD, MVP
    >> http://SteveOrr.net
    >>
    >>

    >
     
    Steve C. Orr [MVP, MCSD], Feb 11, 2005
    #4
  5. Pete

    Pete Guest

    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.
     
    Pete, Feb 11, 2005
    #5
  6. 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

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net



    "Pete" <> wrote in message
    news:...
    > 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.
    >
     
    Steve C. Orr [MVP, MCSD], Feb 11, 2005
    #6
  7. Here's a free masked edit control that might satisfy your requirements:
    http://www.assistedsolutions.com/components/InputMask.aspx

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "Pete" <> wrote in message
    news:...
    > 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.
    >
     
    Steve C. Orr [MVP, MCSD], Feb 11, 2005
    #7
  8. Pete

    Pete Guest

    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
     
    Pete, Feb 11, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,367
    Michael Borgwardt
    May 30, 2004
  2. jack
    Replies:
    1
    Views:
    489
  3. Simon
    Replies:
    2
    Views:
    347
    Pierre Couderc
    Sep 2, 2004
  4. Michael
    Replies:
    4
    Views:
    467
    Matt Hammond
    Jun 26, 2006
  5. Berehem
    Replies:
    4
    Views:
    592
    Lawrence Kirby
    Apr 28, 2005
Loading...

Share This Page