Forums

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for .NET (v4.x)  /  Limit TextField to numbers

Forum Thread - Limit TextField to numbers

 Feb 07 2019 11:31 AM
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.
 Feb 07 2019 1:18 PM
Posted by a ceTe Software moderator
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
 Feb 08 2019 3:21 AM
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?
 Feb 08 2019 11:41 AM
Posted by a ceTe Software moderator
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
 Feb 08 2019 11:45 AM
Posted by a ceTe Software moderator
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
 Feb 12 2019 4:15 AM
Thanks for the answer. I will see if we can upgrade to the current version. Cheers.

All times are US Eastern Standard time. The time now is 3:34 PM.