Validating windows key
The member ‘rc’ (or return code) is used to communicate back if the validation was successful or not.In the latter case, we set rc to false, and also display an error message.Another thing I like to do is to display the validation error message on the form in an otherwise hidden field: The problem with our last solution is that if the user saves a partially filled form, and picks it up at a later time, that error message that popped up is long gone, and the only indication that there is something wrong with the form is the modified field color.One of the questions I get asked again and again is how to validate a field value in an Acro Form with a custom validation script.Adobe provided a lot of infrastructure to do that with just a simple script.Let’s take a look at how to do that with a text field that is only supposed to have a value of either ‘AAAA’ or ‘BBBB’ (yes, I know that this does not make much sense in a real PDF form).So, if the user enters ‘01234’ we should see an error message that would instruct the user about what type of data is valid for this field.
To start, we create a text field and bring up the properties dialog for the field.
Then we select the “Validate” tab to see the validation options: The default is that the field will not get validated.
When you play around with the function, you’ll notice that the validation function is only called when the focus leaves the field, so you have to click outside of the field to actually make that error message pop up.
In that case, the previous value of the field is restored, and the user has to enter the data again.
For numeric fields, there is a convenient way to validate a value range, but we want to select to run a custom validation script.After the “Edit” button is clicked, a new window will open that allows us to edit the new script: As I mentioned before, information is passed to the validation function in the event object, and in the code we see that the member ‘value’ is used to communicate the current value of the field.