devxlogo

Validate the Date in Javascript

Validate the Date in Javascript

 //validation of From Date//Here FromDay,FromMonth,FromYear & ToDay,ToMonth,_ToYear are the names ofthe form fields corresponding to from date and to _dates. Assuming thatthese are drop down fields on the form.function validateFromDate(){	var dt =document.formName.FromDay.options_[formName.FromDay.selectedIndex].value;	var mon =document.formName.FromMonth.options_[formName.FromMonth.selectedIndex].value - 1;	var yr =document.formName.FromYear.options_[formName.FromYear.selectedIndex].value;//Now construct a Javascript date object	var now = new Date(yr,mon,dt);	fromTime = now.getTime();	if(!(now.getDate() == dt && now.getMonth() _== mon && now.getFullYear() ==yr))	{		alert("Invalid From Date!!!");		return false;	}	else	{		isFromDate = true;		return true;	}}
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist