Results 1 to 2 of 2

Thread: Date Validation

  1. #1
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 93 Times in 89 Posts

    Re: Date Validation

    I'm away from my Javascript book, but I think there is an alternative way to use Date() to construct a date from strings, something like Date("yyyy", "mm, "dd") but you'll need to look that up. You then should be able to do some kind of literal comparison with today's date.

  2. #2
    5 Star Lounger
    Join Date
    Jan 2001
    austin, Texas, USA
    Thanked 0 Times in 0 Posts

    Date Validation

    <font color=blue>SOLVED -- Beer contest has been witdrawn. <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20> After some rest this weekend and a re-look at the code it looks like i was getting more complicated than needed. I now have a validation function that enforces proper formatting and blocks input with out of range years and dates after today. Still am not crazy about Javascript but it *is* kind of growing on me. <img src=/S/frank.gif border=0 alt=frank width=15 height=15> </font color=blue>

    I am trying to polish up my validation code and want to test a date to make sure it is not after today's date. In my researches I have discovered the Date() function in Javascript and it seems a little hard to work with in terms of comparing string values. Does anyone have some code that takes a formatted textbox value and tests for being on or before Today?

    I am trying to avoid drop-downs on the date fields and have managed to enforce that input must be MM/DD/YYYY format and can test for a year value >1900 (for the bottom limit) and can test for a year > Today's year but beyond that things get sticky.

    Javascript supports parsing new Date() into Day, Month and Year but the *values* for Day and Month are 0-indexed integers (for example, Monday --> 1; Sunday being 0 and March -->2; January being 0. (don't quote me on that, I'm not certain which day is '0' but you get the idea.)). Testing MM/DD/YYYY againsts Javascript's Day and Month indexes is obviously not going to be all that easy. I have thought of taking the raw Date() output, which is, for example, Wed_May_14_15:26:27_CDT_2004 (underscores to indicate spaces in the actual output) and converting this output to string and then parsing away. I'd have to set up Select Case statements to translate the MMM text to MM (integer) to match the textbox value, which is somewhat painful but not all that bad.

    However, being a lazy programmer, I wondered if anyone has already developed a less cumbersome solution. Ideally, I should be able to directly compare MM/DD/YYYY against some kind of Date() function that matches the textbox value.

    Any help would be greatly appreciated and may result in a fed exed case of beer!
    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts