August 24, 2012 by Nitesh

Simple Date validation using Regex in Javascript

Many of us find difficulties while validating the date field in JavaScript. This is a simple example where I will explain you the basics of validating a date field using JavaScript. So, follow the steps below and get date validated on your form in few minutes:

In your JavaScript section of the HTML page, define the following function

function checkdate(dd,mm,yy)
var returnval=false;
var dayobj = new Date(yy, mm-1, dd)
if ((dayobj.getMonth()+1!=mm)||(dayobj.getDate()!=dd)||(dayobj.getFullYear()!=yy))
     alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
return returnval;

You are done!! Call this function passing date, month and year values in numbers and see the output!!


Support us!

If you like this site please help and make click on any of these buttons!

Powered by WordPress Popup