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
Cut and Paste Code
Cut 'n' paste code for the above Example
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.