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 = newDate(v2.Value);

with this:

var pickeddate = newDate(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

functiondateValidate(inputField)
{
    var pickeddate =  newDate(inputField.value);
    var todayDate =  newDate();
    if( pickeddate > todayDate )
    {
       returntrue;
    }
    else
    {
        alert("Enter a valid Date");
    } 
}

DEMO.

Post a Comment for "Javascript To Validate Date Entered"