Return to Snippet

Revision: 80331
at March 5, 2020 18:47 by jlustre


Initial Title
Validating a Date Format

Initial Description
This is used to validate a date in a specific format. The code example is to validate whether it is a valid dd/MM/yyyy Date Format.

Initial Code
function ValidateDateFormat(input) {
    var dateString = input.value;

    var regex = /(((0[1-9]|1[0-2])\/(0|1)[0-9]|2[0-9]|3[0-1])\/((19|20)\d\d))$/;

    //Check whether valid dd/MM/yyyy Date Format.
    if (regex.test(dateString) || dateString.length == 0) {
        ShowHideError("none");
    } else {
        ShowHideError("block");
        input.focus();
        input.select();
    }
};

Initial Tags
date, validation

Initial Language
JavaScript

Initial URL