Avatar

Level 5

That worked great!  One more question:  The field is now displaying the current date by default.  Is there a way to just make it be blank for entry by user?  Thanks again.

Here's the edited script for the benefit of others:

//Custom Date Validation Java Script for entering dates using numbers only

//courtesy of Ricardo Falegnami and BR001

// adding slashes

var newDate = this.rawValue;

// validate date

if (newDate != "") { // process non-empty string

    var oMyDate = [];

     oMyDate[0] = util.scand("mmddyyyy", newDate);

    oMyDate[1] = util.scand("mmddyy", newDate);

    oMyDate[2] = util.scand("mddyyyy", newDate);

    oMyDate[3] = util.scand("mmdyyyy", newDate);

    oMyDate[4] = util.scand("mdyyyy", newDate);

    oMyDate[5] = util.scand("mdyy", newDate);

    var isDate = false;

 

    for (var i=0; i<oMyDate.length; i++) {

        if (oMyDate[i] !== null) {

            this.rawValue = util.printd("mm/dd/yyyy", oMyDate[i]); // strict format

            isDate = true;

            break;

        }

    }

// Stay in field if invalid

    if (isDate === false) {

        app.alert("Invalid date entered -- please use MMDDYYYY (e.g., 10152014)", 0, 1, "Date Validation"); // check validity

        this.rawValue = "";

        xfa.host.setFocus(this)();

    }

}