How to Check if a PDF Form Value is an Armstrong Number
Question details
The user needs to set up a calculated PDF form field that determines whether a number entered into a field named 'Check' is an Armstrong number, and returns true or false in another field.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating dynamic and interactive PDF forms with advanced calculated fields
- Observed behavior
- The user wants the destination form field to dynamically output 'true', 'false', or remain empty based on a specific mathematical condition evaluated from another input field.
Ensure you are using a PDF editor that supports interactive form creation and custom JavaScript calculation scripts, and that you have added at least two text fields (an input and an output) to your document.
Use Custom JavaScript in a Calculated Form Field
Implement a custom JavaScript script in the destination field's properties to read the source field, perform the mathematical logic, and output the result.
An Armstrong number is a number that equals the sum of its own digits, each raised to the power of the total number of digits. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153.
Since standard PDF formula options only support basic arithmetic, you must use a custom calculation script to parse the digits, calculate the powers, and compare the sum to the original input.
Open your PDF document in a capable PDF editor and switch to the Form creation or editing mode.
Confirm you have a text field named 'Check' for the user's input, and a separate text field created for displaying the final 'true' or 'false' result.
Right-click the destination text field and select 'Properties'. Navigate to the 'Calculate' tab within the properties dialog box.
Choose the 'Custom calculation script' option and click 'Edit'. Write a JavaScript snippet that retrieves the value from the 'Check' field. The script should verify the input is numeric, loop through each digit to raise it to the power of the input's length, and add the results together. Finally, instruct the script to return 'true' if the sum matches the original input, 'false' if it does not, and an empty string if the input is non-numeric.
Save your script and close the properties window. Exit form editing mode and type an Armstrong number (such as 9, 153, or 370) into the 'Check' field to verify that the destination field updates accurately.

Create Interactive PDF Forms Easily with WPS Office
WPS Office includes a comprehensive PDF editor that allows you to effortlessly design interactive forms, insert text fields, and manage document properties.
- 1. Open Your Document in WPS PDF: Launch WPS Office and open your existing PDF or create a new one using the WPS PDF tool.
- 2. Access the Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal the interactive form creation menu.
- 3. Insert Text Fields: Click the 'Text Field' button and draw the input and output boxes directly onto your document.
- 4. Configure Field Properties: Double-click any form field to open its properties, allowing you to customize its appearance, format, and interactive behaviors.

Frequently Asked Questions
What exactly is an Armstrong number?
An Armstrong number (sometimes called a narcissistic number) is a number that equals the sum of its own digits, with each digit raised to the power of the total number of digits. For example, 370 is an Armstrong number because it has 3 digits, and 3^3 + 7^3 + 0^3 = 27 + 343 + 0 = 370.
Why is my PDF form calculation script not running?
If your script is not producing a result, check for syntax errors in your JavaScript code. Also, verify that the calculation order is set correctly in your form properties; the 'Check' input field must be evaluated before the destination field attempts to run its script.
Can I use standard built-in formulas for this task?
No, standard PDF calculation formulas only support basic arithmetic operations like sum, product, and average. Because checking for an Armstrong number requires splitting strings and using exponents, a custom JavaScript script is required.




