Skip to content Skip to sidebar Skip to footer

Javascript To Validate Date Entered

I am new to Javascript programming and I am trying to validate a date entered into an from a calender snippet which is obtained from an external Javascript file. I am

Solution 1:

It is not working since there is a issue in your code, just replace this:

var pickeddate = new Date(v2.Value);

with this:

var pickeddate = new Date(v2.value);   // 'value' should be in lower case

Since, it was not correct, the pickeddate was always undefined and code didn't worked.


Solution 2:

You may try this

HTML

<input size="12" id="inputField" name="inputField"  autofocus="" type="date"     onblur="return dateValidate(this)"/>

JS

function dateValidate(inputField)
{
    var pickeddate =  new Date(inputField.value);
    var todayDate =  new Date();
    if( pickeddate > todayDate )
    {
       return true;
    }
    else
    {
        alert("Enter a valid Date");
    } 
}

DEMO.


Post a Comment for "Javascript To Validate Date Entered"