Allow user to enter only numbers for a date and populate with slashes, then validate
Hello,
I'm using Acrobat X. I have many forms with many date fields that I would like to allow the user to fill in with just numbers and populate it with slash separators as soon as they press TAB. Right now I'm using Format > Special > Arbitrary Mask, with a value of "99/99/9999". This works in terms of formatting, but doesn't allow for date validation. I don't like to use the built-in date formatting because it requires the user to type the slashes (or dashes).
The other problem with using the "99/99/9999" method is that if you want to go back and correct your date, if you click in the middle of the field and press either BACKSPACE or DELETE, it pops up an error, "The value entered does not match the format of the field...". The only way you can correct it without an error is if you position the cursor at the very end of the field and press BACKSPACE.
So what I would really like to do is allow the user to move quickly by just typing numbers (no slashes or dashes), have the slashes populate automatically upon pressing TAB, and perform at least some rudimentary date validation. I tried using some of the code below which I borrowed from other people, but I still couldn't make it work.
I'd greatly appreciate any help.
// adding slashes
if (event.value!="") event.value = event.value.substring(0,2) + "/" + event.value.substring(2,4) + "/" + event.value.substring(4)
// validate date
if(event.value != "") { // process non-empty string
var oMyDate = util.scand("dd-MM-yyyy", event.value); // convert to date object
if(oMyDate == null) app.alert("Invalid date entered!", 0, 1), "Date Validation"; // check validity
event.value = util.printd("dd-MM-yyyy", oMyDate); // strict format
}
Kamran Grasselli