function checkNum(str, min, max) { if ((str.length < min) || (str.length > max)) { alert("Date of Birth must be exactly 10 characters") return false } var mm = str.charAt(0) + str.charAt(1) var dd = str.charAt(3) + str.charAt(4) var yy = str.charAt(6) + str.charAt(7)+ str.charAt(8)+ str.charAt(9) if (str.charAt(2) != "/" || str.charAt(5) != "/" ) { alert("Try the MM/DD/YYYY date format, please.(1)") return false } if (yy == 0 || mm == 0 || mm > 12 || dd == 0 || dd > 31) { alert("Try the MM/DD/YYYY date format, please.(2)") return false } if (mm == 4 || mm == 6 || mm == 9 || mm == 11) { if (dd > 30) { alert("Invalid date 2") return false } else if (dd > 31) { alert("Invalid date 3") return false } } if ( mm == 2) { div = yy / 4 if (div == 0 && dd > 29) { alert("Invalid date 4") return false } if (div != 0 && dd > 28) { alert("Invalid date 5") return false } } // if the date is valid, check is it is after today's date todaydate = new Date() todaystr=((todaydate.getMonth()+1)+ "/" +todaydate.getDate() + "/" +(todaydate.getYear()+1900)); var todaymm = parseInt(todaystr.charAt(0) + str.charAt(1)) var todaydd = parseInt(todaystr.charAt(3) + str.charAt(4)) var todayyy = parseInt(todaystr.charAt(6) + str.charAt(7) + str.charAt(8) + str.charAt(9)) if (Date.parse(str) > Date.parse(todaystr) ) { alert("Enter a date before today's date, please.") return false } else { return true } }