Quantcast
Channel: Adobe Community : All Content - LiveCycle Designer
Viewing all articles
Browse latest Browse all 5571

Custom date validation script

$
0
0

I have the script below that I used for a PDF form in Acrobat X, but it doesn't work when I enter it in the Javascript editor in ES2.  Is it possible to create a script that does the same thing in LiveCycle Designer ES2?  I would like to let the user enter a date using numbers only, and have the field add in slashes as needed, in addition to validating for a proper date.   Thanks for any assistance.

 

//Acrobat date validation

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

//courtesy of Ricardo Falegnami

 

// adding slashes

var newDate = event.value;

// 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) {

            event.value = 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

        event.value = "";

        event.target.setFocus();

    }

}


Viewing all articles
Browse latest Browse all 5571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>