9

I have a writeable PDF form made in Acrobat Professional. I want to validate that a numerical entry is in a certain range [a,b]. If it is not, I want an alert to pop up with the message, "Please contact Larry at XXX-XXX-XXXX to get your form processed." Can someone write up a quick snippet of code that does this for a PDF? I know how to do it for a web form.

user438293456
  • 596
  • 3
  • 6
  • 19

2 Answers2

11

You could do something like this:

if (event.value > 3 && event.value < 10) {
    event.rc = false;
    app.alert({
        cMsg: "Please contact Larry at xxx to process your form.",
        cTitle: "My Window Title",
        nIcon: 0,
        nType: 1
    });
}

You can enter this validation script by editing the properties of a field. Go to "Validate Tab", click "Run custom validation script", then "Edit...". Type the code into the JavaScript Editor window, and then click "Ok" and "Close".

alt text
(source: skitch.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Kyle Ridolfo
  • 623
  • 5
  • 13
  • This answer looks great. Can you provide a little more detail exactly where to insert this script so future readers can get the full picture? – Doug Neiner Nov 21 '09 at 02:30
  • Good idea :) Hope the screenshot and description help. – Kyle Ridolfo Nov 21 '09 at 17:58
  • 1
    In many cases, a regular expression can also be used, something like `var RegExp = /[1-2][0-9]/; if (!RegExp.test(event.value) && event.value) {...}`. The second condition is to allow empty value. – texnic Jan 03 '13 at 11:38
3

You can do this without javascript as long as you are OK with the default error message.

  1. In Acrobat, while in edit mode, right click on the field
  2. On the Format tab, set the format to Number
  3. On the Validate tab, choose the second option and set a low and a high number for your range.

Now, when a user tries to supply an answer outside that range, an popup box will alert them to the error.

Doug Neiner
  • 65,509
  • 13
  • 109
  • 118
  • Right, but I want to use a different message in the alert box. Was that not clear? I'll emphasize that in the question more. – user438293456 Nov 21 '09 at 00:45
  • Ok, so my answer doesn't cover the custom message, but I'll leave it for other viewers. @Kyle Ridolfo's answer below should be what you want. – Doug Neiner Nov 21 '09 at 02:49