How to Validate a Learner ID Number in a PDF Form
Question details
The user needs to enforce a specific format for a learner ID number in a PDF registration form using custom validation scripts.

- Product
- PDF Form Editors
- Device & OS
- not provided
- Scenario
- Creating or editing a PDF registration form where users must input a properly formatted Learner ID.
- Observed behavior
- The form needs a custom validation script to check the number of digits, allowed characters, and specific patterns of the entered ID.
Determine the exact format of the Learner ID you want to enforce, including the required number of digits, any letter prefixes, and required dashes, before writing the validation script.
Use Custom JavaScript Validation in PDF Form Properties
Apply a custom JavaScript validation script to the text field to enforce your specific Learner ID format.
Because Learner IDs can vary across institutions (e.g., exactly 8 digits, or starting with specific letters), you must define the required pattern using Regular Expressions (Regex) in a custom script.
When the user finishes typing and exits the text field, the script will evaluate the input and reject any entries that do not match the specified pattern.
Open your PDF form in edit mode, right-click the text field intended for the Learner ID, and select 'Properties' from the context menu.
In the Text Field Properties dialog box, click on the 'Validate' tab at the top.
Select the 'Run custom validation script' radio button and click the 'Edit' button next to it.
Enter your JavaScript code using Regular Expressions to match your ID format. For example, to enforce exactly an 8-digit number, type: var r = /^\d{8}$/; event.rc = r.test(event.value);
Click 'OK' to save the script, close the properties panel, and test the form field to ensure invalid entries are rejected.

Create and Validate PDF Forms with WPS PDF
Easily create professional registration forms, add text fields, and manage form data using WPS Office. Its comprehensive PDF tools allow you to seamlessly set up and deploy fillable forms.
- 1. Open PDF in WPS: Launch WPS Office and open your PDF registration form.
- 2. Access Form Tools: Navigate to the 'Form' tab in the top ribbon to view all interactive field options.
- 3. Edit Field Properties: Double-click the Learner ID text field to open its properties panel.
- 4. Set Formatting: Go to the format or validation settings to apply formatting rules, ensuring accurate user input.

Frequently Asked Questions
What is the standard JavaScript regular expression for an 8-digit Learner ID?
To validate an exactly 8-digit number, use the regular expression /^\d{8}$/. In a PDF validation script, you apply it using: var regex = /^\d{8}$/; event.rc = regex.test(event.value);
Can I validate PDF form fields without using JavaScript?
Yes, for basic formats like dates, times, or standard number formats (e.g., percentages or zip codes), you can use the built-in 'Format' tab in the text field properties instead of writing a custom script.
Why is my PDF validation script not working?
Ensure that JavaScript is enabled in your PDF viewer's preferences. Additionally, check your script for syntax errors and verify that the regular expression perfectly matches the intended input format without hidden spaces.
How do I show a custom error message when an invalid Learner ID is entered?
You can trigger an alert in your validation script to notify the user. Add the following logic: if (!event.rc) { app.alert('Invalid Learner ID format. Please try again.'); }




