Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PdfAcroFormValueFormat.KeystrokeScript Property

Gets or sets the JavaScript to be performed when the user modifies a character in a. This action may check the added text for validity and reject or modify it.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v24.2.Core.dll

NuGet Package: DevExpress.Pdf.Core

#Declaration

public string KeystrokeScript { get; set; }

#Property Value

Type Description
String

The keystroke JavaScript. For JS API reference, use JavaScript for Acrobat API Reference

#Remarks

The code sample below shows how create a text box and specify the value format using JavaScript:

var scriptBox = 
new PdfAcroFormTextBoxField("script", 1, new PdfRectangle(10, 170, 100, 200));
scriptBox.ValueFormat = new PdfAcroFormValueFormat();

//Specify a script that allows you to enter only numbers
//in the "x-x-x" format:
scriptBox.ValueFormat.FormatScript = "if (event.value != \"\") {" +
    "var value = event.value;    " +
    "event.value = \"\";    " +
    "for(var i = 0; i<value.length - 1; i++)" +
    "   event.value += value.charAt(i) + \"-\";" +
    "event.value += value.charAt(value.length - 1);}";
scriptBox.ValueFormat.KeystrokeScript = "var re = /^[0-9]+$/;" +
    "if (event.value != \"\") {" +
    "   event.rc = re.test(event.value);" +
    "}";
See Also