Date Validation - DD/MM/YY Format

Date Validation in JS - date/month/year format

Javascript Tutorials

Date Validation - dd/mm/yyyy

Cross browser Javascript Date Validation

In forms when asking for date inputs it's a good practice to validate the date value using client side JavaScript validation in addition to your programming language validation. The following example shows how you can do this for the dd/mm/yyyy format.

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

Javascript Date Validation Example

Cross browser Javascript Date Validation (dd/mm/yyyy)

Enter a Date (dd/mm/yyyy) :

Cut and Paste Code

Cut 'n' paste code for the above Example

Java-script Code


Explanation of the Code

The JavaScript has the following main functions:

  • 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 day, month and year integers. They are each validated seperately and combined together.

  • 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!