Limit TextField to numbers

Limit TextField to numbers

Forum member · Feb 7, 2019
Hello, is it possible to limit user input to numbers, either floating point numbers or integers (I'd like both)? According to short google searches it's possible with certain other software (like certain Adobe products) by defining functions that check the input, but I don't know if DynamicPDF can generate code like that, or if it can, how portable it would be. Any input would be appreciated. Cheers.

Re: Limit TextField to numbers

Support · Feb 7, 2019
Hello, There isn't a way to do that on the form field page element directly. We'll check and get back to you on if there is any way to do this reliably using JavaScript. Thanks, ceTe Software Support Team

Re: Limit TextField to numbers

Forum member · Feb 8, 2019
I wasn't even aware that you can use JavaScript scripts in the generator. Is that possible in v4? I don't know if upgrading is an option at this point, I'm afraid. Where is that API documented?

Re: Limit TextField to numbers

Support · Feb 8, 2019
There is document level JavaScript in v4, but form field level JavaScript was introduced in v9. With v9 or greater, you can use the following code to accomplish this: Document document = new Document(); Page page = new Page(); document.Pages.Add(page); TextField textField = new TextField("txt", 50, 75, 150, 100); ; textField.DefaultValue = "0"; textField.ToolTip = "Enter only Numbers"; textField.ReaderEvents.OnBlur = new JavaScriptAction(" var no = this.getField(\"txt\").value; if( isNaN(no)) { app.alert(\"Please Enter number in the text field\"); } "); page.Elements.Add(textField); document.Draw(@"c:\temp\output.pdf"); Thanks, ceTe Software Support Team

Re: Limit TextField to numbers

Support · Feb 8, 2019
You can find the documentation in this area of our site: User Manuals The latest versions are listed at the top of the page, and previous versions listed below that. Thanks, ceTe Software Support Team

Re: Limit TextField to numbers

Forum member · Feb 12, 2019
Thanks for the answer. I will see if we can upgrade to the current version. Cheers.