Javascript Date Validation

Cross Browser Date Validation in JS

Javascript Tutorials

Date Validation

Javascript for Date Validation - mm/dd/yyyy format

Its good practice to validate form date values using client side JavaScript validation along with your programming language validation. The following example shows how you can do this for the mm/dd/yyyy format.

We have also provided the javascript date validation for the dd/mm/yyyy format.

JS Date Validation Example

Validate Date using javascript


Enter a Date (mm/dd/yyyy) :

Cut and Paste Code

Cut 'n' paste code for the above Example

Java-script Code

HTML Code

Explanation of the Code

The JavaScript has the following main functions:

isDate Function

Function isDate is used to verify if the given value is a valid date in the format (mm/dd/yyyy) : This function first specifies the non-digit character which is allowed in the date ("/" is used here). You can also specify the year range between which the date is valid. These changeable values are declared in the lines (found in the beginning of the code) :

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

If the valid date character is changed please make sure you replace it in the HTML and Javascript code too.

Now the date string is seperated into the month, day and year integers. They are each validated seperately and combined together.

ValidateForm Function

Function ValidateForm is used to check if the date field is valid on form submission

Please like, +1, link to and share this SmartWebby resource if you found it helpful. Thanks!