0

enter image description here

function checkDate(date)
{
        //how to use this function since many people recommend this one
    isLeap = new Date(date, 1, 29).getMonth() == 1;
    return isLeap;

}

In html script, i wrote it as but i can't validate my Date of Order. I need to use javascript and it should be able to validate it including leap year. The function I used above can't work. Any helps will be appreciated.

user3066033
  • 399
  • 1
  • 4
  • 9
  • I'm sorry for late to reply. Here I updated with the form, i can't validate Date of Order using javascript, please help me go through this. – user3066033 Dec 09 '13 at 13:53
  • A screenshot doesn't help : http://jsfiddle.net/. –  Dec 09 '13 at 14:01
  • http://jsfiddle.net/W82GA/1/ can press this link? – user3066033 Dec 09 '13 at 14:14
  • Your code is messy. Clean it up, fix unclosed tags, remove the least interesting parts (customer id, recipient name...), then try to ask yourself where the problem(s) should be located. After that, include your link into the question, and tell us what you've found so far. Example : "The function I used above can't work.". Why do you think it doesn't work currently? –  Dec 09 '13 at 19:09
  • Are you trying to check if a year is a leap year? This [question](http://stackoverflow.com/questions/16353211/check-if-year-is-leap-year-in-javascript) has you covered. – ahalbert Dec 04 '13 at 15:30

1 Answers1

0

To check if it's leap year :

var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));

to check if the extra day is valid -- is to check how many days were in that month (and if they equal to dd):

32 - new Date(2000, 1, 32).getDate() //1 here is FEB

do if some says : 29 feb 2000

so 32 - new Date(2000, 1, 32).getDate()//29

which is fine . cuz 29==29.

BUT

do if some says : 29 feb 2001

32 - new Date(2001, 1, 32).getDate()//28

and 28!=29 so it's not valid date.

Royi Namir
  • 144,742
  • 138
  • 468
  • 792