Validate Date JS
Make sure dates entered into form fields are valid.
function CheckDate(THISDATE) { //Copyright © 2002 Booshway Enterprises, Inc. all rights reserved v1.0 var err=0 a=THISDATE.value if (a.length != 10) err=1 f = a.substring(0, 4)// year f c = a.substring(4, 5)// '/' b = a.substring(5, 7)// month b e = a.substring(7, 8)// '/' d = a.substring(8, 10)// day d if (b<1 || b>12) err = 1 if (d<1 || d>31) err = 1 if (f<1900) err = 1 if (b==4 || b==6 || b==9 || b==11){ if (d==31) err=1 } if (b==2){ var g=parseInt(f/4) if (isNaN(g)) { err=1 } if (d>29) err=1 if (d==29 && ((f/4)!=parseInt(f/4))) err=1 } if (err==1) { alert(THISDATE.name + ": " + THISDATE.value + ' is not a valid date. Please re-enter. Format YYYY/MM/DD.'); THISDATE.focus(); } return err; }