SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting invalid dates in JavaScript

    How can I find out how many days there are in a month for example to validate this information?

    If I set the date as 29 Feb 2002 it ends up as 1 March 2002 - so no validation there.

    Cheers,

    Dale

  2. #2
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Detecting invalid dates in JavaScript

    Originally posted by dale_burrell
    If I set the date as 29 Feb 2002 it ends up as 1 March 2002 - so no validation there.
    Not being a JS expert, that sounds like it automatically validated the date and pushed it on one if it was invalid. If you want to overide that you'll have to write your own function. This can vary in complexity. A friend of mine wrote a brilliant function in VBS to do this, but it's pretty complex and completely infallible ... it can calculate the Roman calendar all the back to 1 BC and as forward as far as you like. What you need could probably be simpler though. This looks like a good one:

    http://javascript.internet.com/forms/val-date.html

    It handles leap years too. Google is a wonderful thing -- you should try it some time ...

  3. #3
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As it happens I found exactly that article using google - after reading the notes about checking google in an earlier message

  4. #4
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good stuff!


Bookmarks

Posting Permissions

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