Change PDF Form Text Color When a Value Is Below 5 in Adobe Acrobat
Question details
Change a PDF form field's text color to red when its numeric value is below 5, including when the value is zero.

- Product
- PDF form editor with JavaScript support, such as Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- A PDF form needs conditional text coloring based on a numeric field value.
- Observed behavior
- A truth test can skip zero because JavaScript treats it as false, preventing the value from being colored red.
Open the PDF in an editor that supports form field JavaScript, such as Adobe Acrobat Pro, and identify the numeric field to validate. This example applies the color to the field being edited.
Use a validation script to color the numeric field
Apply this script to the numeric field so values below 5, including zero, display in red.
In Adobe Acrobat Pro, open the PDF and select All tools > Prepare a form.
Double-click the numeric field, such as Quantity, and select the Validate tab in its properties.
Select Run custom validation script, click Edit, and enter: var A = Number(event.value); if (A < 5) event.target.textColor = color.red; else event.target.textColor = color.black;
Click OK to close the script editor and field properties, save the PDF, and test the field with 0, 4, and 5. Values 0 and 4 should be red; 5 should be black.

Manually Highlight Low Values in WPS PDF
For a static PDF, use WPS PDF's text editing tools to manually color values below 5 red. This is a manual workaround and does not automatically change an interactive form field's color when its value changes.
- 1. Open the PDF: Open WPS Office, choose Open, and select the PDF containing the value.
- 2. Select the text: Choose Edit PDF and select the text containing a value below 5.
- 3. Change the color: Use the text color control in the editing toolbar to choose red, then save the PDF.

Frequently Asked Questions
Why does zero not turn red in my PDF form?
A condition such as if (A) treats 0 as false. Compare the numeric value directly with 5 instead, using if (A < 5).
Where do I add the validation script in Acrobat?
Open All tools > Prepare a form, double-click the field, and go to Validate > Run custom validation script > Edit.
Why does an empty field turn red?
JavaScript converts an empty string to 0 when using Number(''), and 0 is below 5. Add an explicit blank-value check before the numeric comparison if blanks should stay black.
Will the color change work in every PDF viewer?
No. The automatic color change depends on the viewer supporting Acrobat form JavaScript. Test the saved PDF in the viewer your recipients will use.




