Hi
Date validation is very much required function in web application hare is the function which checks the date validity that it is in "MM/dd/yyyy" format or not
function checkdate(input) {
var validformat = /^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
var returnval = false
if (input != null && input != "") {
if (!validformat.test(input))
returnval = false;
else { //Detailed check for valid date ranges
var monthfield = input.split("/")[0]
var dayfield = input.split("/")[1]
var yearfield = input.split("/")[2]
var dayobj = new Date(yearfield, monthfield - 1, dayfield)
if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield)) {
returnval = false;
}
else
returnval = true;
}
}
else {
returnval = true;
}
return returnval
}
No comments:
Post a Comment