<<
p72is Date
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
/*
NAME: p72isDate()
AUTHOR: Chris Hembrow [ chris at pixelseventy2 dot net ]
CREATED: jan2004
DESCRIPTION: validates a given date ( returns a boolean )
can also validate that a date is in the past
PARAMS: p72day - Integer - the day of the month
p72month - Integer - the month
p72year - Integer - the year
p72noFuture [optional] - boolean - false allows future dates, true prevents them
*/
function p72isDate(p72day,p72month,p72year,p72noFuture) {
if ( p72day <= 0 || p72month <= 0 || p72year <= 0 ) return false;
if ( p72day > 31 || p72month > 12 ) return false;
if ( p72day == 31 && ( p72month == 4 || p72month == 6 || p72month == 9 || p72month == 11 ) ) return false;
var p72isLeap = ( p72year % 4 == 0 && ( p72year % 100 != 0 || p72year % 400 == 0 ) )
if ( p72month == 2 && ( p72day > 29 || ( p72day > 28 && !p72isLeap ) ) ) return false;
if ( p72noFuture ) {
d1 = new Date();
d2 = new Date( p72year , p72month-1 , p72day );
if ( d2 > d1 ) return false;
}
return true;
}