Custom Validate JS Scripts

Applies To: Information Worker for SharePoint 2013/2016 and Cloud


Validation runs when the associated field value changes. The purpose of field level validation is to verify that the input to a field is entered correctly.



All JavaScript scripts are executed as the result of a particular event. For each of these events, JavaScript creates an event object. During the occurrence of each event, you can access this object to get and possibly manipulate information about the current state of the event. Each event has a type and a name property that uniquely identify the event. This section describes all the events, listed as type/name pairs, and indicates which additional properties, if any, they define.




Is the value that the field contains when it is committed. For example, the following JavaScript verifies that the field value is between zero and 100:

if (event.value < 0 || event.value > 100) {
 app.alert("Invalid value for field " +;
 event.rc = false;

The target object that triggered the event. In all mouse, focus, blur, calculate, validate, and format events, it is the Field object that triggered the event. In other events, such as age open and close, it is the Doc or this object.


Field properties and methods affect field-level attributes

calcOrderIndex, charLimit, comb, currentValueIndices, defaultValue, doNotScroll, doNotSpellCheck, delay, doc, editable, exportValues, fileSelect, multiline, multipleSelection, name, numItems,page, password, readonly, required, submitName, type, userName, value, valueAsString, clearItems, browseForFileToSubmit, deleteItemAt, getItemAt, insertItemAt, setAction, setItems,signatureInfo, signatureSign, signatureValidate.


Field properties and methods affect widget-level attributes

alignment, borderStyle, buttonAlignX, buttonAlignY, buttonPosition,buttonScaleHow, buttonScaleWhen, display, fillColor, hidden, highlight,lineWidth, print, rect, strokeColor, style, textColor, textFont, textSize, buttonGetCaption, buttonGetIcon, buttonImportIcon, buttonSetCaption, buttonSetIcon, checkThisBox, defaultIsChecked, isBoxChecked, isDefaultChecked, setAction, setFocus


Get reference to data field or control:


Scripts, which are executed on specific control (e.g. Button click) have “” variable set to current control.

event.value - gets value of current control.

Manipulate fields /controls

Get field value:

Getting the value of the field data that the user has entered. Depending on the type of the field, may be a String, Date, or Number.

var fieldValue = this.getField("TextField1").value;   

Getting string value from field

var fieldStringValue = this.getField("TextField1").valueAsString;   

Change field value:

event.value = 'Changed value';     

Show alert message:

app.alert({cMsg: "Error! Try again!", cTitle: "Title here" });
cMsg A string containing the message to be displayed.
nIcon (optional) An icon type. Possible values are these: 0 — Error (default) 1 — Warning 2 — Question 3 — Status
nType (optional) A button group type. Possible values are these: 0 — OK (default) 1 — OK, Cancel 2 — Yes, No 3 — Yes, No, Cancel
cTitle (optional, Acrobat 6.0) The dialog box title. If not specified, the title “Adobe Acrobat” is used.

Make control visible / hidden: = false; = true; 

Get data from data source:

dataList = DataSources['ListName'];
this.getField('TextField1').value = dataList[0]['columnName'];



Following code checks on field exit if field equals "Hello World". If it does not, then entered text becomes red

if (event.value != "" && event.value != "Hello World")
    app.alert("The entered value needs to be Hello World"); =;;
{ =;


Scripting reference and more examples can be found in JavaScript for Acrobat API Reference.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.
Powered by Zendesk