PDF Form Field Input Masks/Validation

Hi - I need to provide input mask/validation to PDF forms I’m dynamically creating with aspose.pdf. Need to restrain some form textbox inputs to either date formats or numbers only.

Does this require javascript or are there built-in properties/methods for restraining input for textbox?

In addition to the above, I need to integrate custom javascript to autopopulate current system date into a textbox.

Thank you.

Hi Jason,

Thanks for your inquiry. Yes, you need to use JavaScript to achieve your requirements. Field.Actions has OnModifyCharacter and OnFormat properties used for the purpose. In order to add validation of user entry, AFNumber_Keystroke and AFNumber_Format JavaScript functions may be used. Here is a sample code snippet for numeric value validation.

Moreover, please find a more detailed description about JavaScript functions to format/validate form fields in the following link:

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/FormsAPIReference.pdf

Document doc = new Document("source.pdf");

TextBoxField field = (TextBoxField)doc.Form["textField"];

// http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/FormsAPIReference.pdf
// 2 digits after point
// no separator
// neg style = minus
// no currency

field.Actions.OnModifyCharacter = new JavascriptAction("AFNumber_Keystroke(2, 1, 1, 0, "", true)");
field.Actions.OnFormat = new JavascriptAction("AFNumber_Format(2, 1, 1, 0, "", true)");
field.Value = "123";
doc.Save("out.pdf");

Please feel free to contact us for any further assistance.

Best Regards,