Format a PDF School Year Field as 2022/2023 in Adobe Acrobat
Question details
Create an interactive PDF field that displays a school year such as 2022/2023 while minimizing the digits users must enter.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A form designer wants users to enter a starting year while fixed text or a script supplies the rest of the school year.
- Observed behavior
- The desired field displays consecutive years in the format 2022/2023.
Open the PDF in a version of Adobe Acrobat that can edit form fields, and identify where the school year should appear. Decide whether users should enter both sets of digits or whether the second year should be generated automatically.
Format and Validate the School Year with Acrobat JavaScript
Use a custom validation script to turn entries such as 22 or 2022 into 2022/2023 automatically.
This approach formats the whole field after the user commits the entry; it does not protect individual parts of the displayed value. The example accepts starting years from 2000 through 2098 and requires consecutive years.
In Adobe Acrobat, open the PDF and select All tools > Prepare a form. Add a text field where the school year should appear, or select an existing text field.
Double-click the field to open its Properties, select the Validate tab, and choose Run custom validation script. Click Edit.
Paste this script into the JavaScript editor and confirm the dialog: if (event.value) { var s = String(event.value).replace(/^\s+|\s+$/g, ""); var m = /^(?:([0-9]{2})|20([0-9]{2})|([0-9]{2})\/([0-9]{2})|20([0-9]{2})\/20([0-9]{2}))$/.exec(s); if (!m) { app.alert("Enter a year such as 22, 2022, 22/23, or 2022/2023."); event.rc = false; } else { var n = Number(m[1] || m[2] || m[3] || m[5]); var end = m[4] || m[6]; if (n > 98 || (end && Number(end) !== n + 1)) { app.alert("Enter consecutive years with a starting year from 2000 to 2098."); event.rc = false; } else { event.value = "20" + ("0" + n).slice(-2) + "/20" + ("0" + (n + 1)).slice(-2); } } }
Close field Properties, select Preview in Prepare a form, enter 22, and move to another field. Confirm that the value changes to 2022/2023, then save the PDF.

Use Fixed Text and Separate Year Digit Fields
Use this layout when the fixed portions should not be editable and users can enter both sets of year digits.
Fill an Existing PDF School Year Field with WPS Office
If you only need to complete an existing PDF form, open it in WPS Office and enter the school year in its field. Creating the Acrobat validation script is a separate form-design task.
- 1. Open the PDF: Open WPS Office, choose Open, and select the existing fillable PDF.
- 2. Enter the school year: Click the school year field and enter 2022/2023, or follow the form's instructions if it uses separate digit fields.
- 3. Check and save: Click outside the field to check the displayed value, then use File > Save As to save the completed PDF.

Frequently Asked Questions
Can I enter only 22 and display 2022/2023?
Yes. In Acrobat's Prepare a form tool, add the custom validation script to the text field. After entering 22, move to another field to trigger validation and formatting.
Can the fixed parts of the school year be protected?
Place 20 and /20 as regular PDF text and add separate form fields for the editable digits. The fixed text will not be editable through those form fields.
Does the validation script accept 22/23?
Yes. The example accepts 22/23 and converts it to 2022/2023. It rejects a pair if the second year is not one greater than the first.
Will the script work in every PDF viewer?
No. PDF viewers differ in their support for Acrobat JavaScript. Open the saved form in the recipient's intended viewer and test the field before distributing it.
Can the script format 2099/2100?
Not as written. It restricts starting years to 2000–2098 because its output uses 20 as the prefix for both years. The logic would need to be changed to handle the century transition.




