i'm really sorry i haven't seen they were unavailable at the moment - and i have to leave now so i can't spend time for a detailed answer
i can suggest you to use the Date object in javascript, its doc (netscape only - but it should fit ie) can be found at :
alternatively you can parse it as if it was a string (using substr and index to retrieve the / or ,)
i hope since tomorrow morning someone will pop by and help you, or maybe you will manage with these 2 ideas (actually one is enough ;]), else i'll be here tomorrow
thank you so much! however, seem like it only checks one format which is mm/dd/yyyy
What should i change or add to make it validates all 4 format scenerios:
mm/dd/yyyy
mmm dd, yyyy (e.g. aug 13, 1999)
mm/yyyy
yyyy
Any advices? please help...i'm just a novice in javascript ! Thankssssssssssssssssssssssss
well, here is what i have so far (only for mm/dd/yyyy) Please help me with the other 3 allowable formats :
mm/yyyy
mmm dd, yyyy
yyyy
thanks....
-----
<script>
function validateForm() {
dateCheckMsg = checkDate(document.searchchoice.beg_date_val.value);
if (dateCheckMsg.length > 0) {
alert(dateCheckMsg);
return false;
}
dateCheckMsg = checkDate(document.searchchoice.end_date_val.value);
if (dateCheckMsg.length > 0) {
alert(dateCheckMsg);
return false;
}
}
function checkDate(strDate) {
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var dateSeparator=new Array("/",","
var errMsg="Please use the correct date format for the Publishing Date\n(e.g. mm/dd/yyyy - 4/12/2001)";
var error=0;
if (strDate.length > 0) {
// Checks if the date uses "/," to separate the month, day, and year.
if (strDate.indexOf(dateSeparator) != -1) {
strDateArray = strDate.split(dateSeparator);
// Checks if the data contains month, day, and year.
if (strDateArray.length != 3) {
return(errMsg);
}
// Checks if the values are numeric.
if (isNaN(strMonth) || isNaN(strDay) || isNaN(strYear)) {
return("The Publishing Date must be a numeric value\n(e.g. mm/dd/yyyy - 4/12/2001)"
}
if (intMonth > 12 || intMonth < 1) {
errMsg+="\n - The Month for the Publishing Date is incorrect.";
error=1;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intDay > 31 || intDay < 1)) {
errMsg+="\n - The Day for the Publishing Date is incorrect.";
error=1;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
errMsg+="\n - The Day for the Publishing Date is incorrect.";
error=1;
}
if (intMonth == 2) {
if (intDay < 1) {
errMsg+="\n - The Day for the Publishing Date is incorrect.";
error=1;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
errMsg+="\n - The Day for the Publishing Date is incorrect.";
error=1;
}
}
else {
if (intday > 28) {
errMsg+="\n - The Day for the Publishing Date is incorrect.";
error=1;
}
}
}
if (error == 1) {
return(errMsg);
}
}
// Returns an error if date does not user "/" to separate the month, day, and year.
else {
return(errMsg);
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.