Created
December 13, 2013 16:54
-
-
Save digitalhydra/7947354 to your computer and use it in GitHub Desktop.
validate date function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkDate() { | |
var myDayStr = document.CheckDate.formDate.value; | |
var myMonthStr = document.CheckDate.formMonth.value; | |
var myYearStr = document.CheckDate.formYear.value; | |
var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr; | |
/* Using form values, create a new date object | |
using the setFullYear function */ | |
var myDate = new Date(); | |
myDate.setFullYear( myYearStr, myMonthStr, myDayStr ); | |
if ( myDate.getMonth() != myMonthStr ) { | |
alert( 'I\'m sorry, but "' + myDateStr + '" is NOT a valid date.' ); | |
} else { | |
alert( 'Congratulations! "' + myDateStr + '" IS a valid date.' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment