Validate Date Input

[Total: 0    Average: 0/5]

This script validates a string to be a date literal.

Head Code:


function checkMyDate(_form) {
    var _value = _form.myDate.value;
    var _test = Date.parse(_value)

    if (isNaN(_test)) {
        _form.myDate.value = "";
        alert("Not a valid date!");
    else {
        nDate = new Date(_test);
        _form.myDate.value = nDate.toUTCString();


Body Code:

Example: &quot;10/01/2001&quot;
<form name="checkDateForm">
<input size=30 name="myDate" value="12/29/2002">
<input type="button" value="Check Date" onclick="checkMyDate(this.form)">

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *