Validating date in Java Script

There are lots of method available which uses REG EXP to validate date and are bit complicated to understand. Here is simple and small date validator.

function isValidDate(day, month, year){
var date;
//Get a Date object based on the given day, month and year
//months start at 0 (0-11 instead of 1-12)
date = new Date(year,month-1,day);
return ((day == date.getDate()) && (month == (date.getMonth()+1))
&& (year == date.getFullYear()));
}

Related Post

Converting Date to String object
Converting String to Date object
The Constructor Date(String) is Deprecated since of JDK 1.1 you should not use it
How to prevent browser caching
Installing tomcat in ubuntu/linux

Comments

Leave a Reply




Technology