How to Compare and Validate Email Fields in a PDF Form
Question details
The user needs to validate email inputs in a PDF form by comparing an email field with a confirmation email field and triggering an alert if they do not match.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating or editing an interactive PDF form that requires users to accurately confirm their email address.
- Observed behavior
- A custom validation script is required to compare two specific text fields and display an error message when the values differ, working alongside standard email format validation.
Ensure you have a PDF editor that supports custom JavaScript for forms, and verify that your text fields are accurately named (e.g., 'email' and 'confirmEmail') before applying the script.
Use JavaScript to Compare Email Fields
Add a custom script to the confirmation field to automatically compare its value with the primary email field when the user enters data.
PDF forms support JavaScript for advanced field validation. By running a simple script on the validation trigger of the confirmation field, you can cross-check the data against the primary email field and alert the user immediately if they make a typo.
Open your PDF editor and navigate to the Form Editing or Prepare Form tools.
Right-click the 'confirmEmail' text field (the field where the user re-enters their email) and select Properties.
Navigate to the Validate tab, select the option to run a custom JavaScript, and click Edit.
Input the following script: var email1 = this.getField("email").valueAsString; var email2 = this.getField("confirmEmail").valueAsString; if (email1 != email2) { app.alert("The email addresses you entered do not match!"); }
Save the properties, exit form editing mode, and type different emails into the two fields to ensure the warning alert appears.

View, Fill, and Manage PDF Forms with WPS PDF
WPS Office offers a powerful, intuitive PDF tool that makes interacting with, filling out, and managing interactive PDF forms incredibly simple. Whether you are validating data or signing documents, WPS PDF ensures your workflow remains efficient.
- 1. Download and Install: Download WPS Office for free and install it on your device.
- 2. Open Your Form: Launch WPS PDF and open your interactive PDF form.
- 3. Fill the Data: Navigate through the form fields; WPS PDF will automatically recognize interactive text fields, drop-downs, and checkboxes.
- 4. Save and Export: Once completed and validated, click Save or export the document to share it securely.

Frequently Asked Questions
Can I validate the standard email format (like name@domain.com) in a PDF?
Yes, alongside the comparison script, you can use a regular expression (RegEx) in standard PDF JavaScript to check if the input matches a valid email format structure before comparing the two fields.
Why isn't my JavaScript alert popping up when testing the PDF form?
Make sure you have exited form editing mode and are in preview or view mode. Also, check your PDF viewer's preferences to ensure JavaScript execution is enabled.
What happens if the user leaves both email fields blank?
If both fields are left blank, their values will match (both are empty strings), so the mismatch alert will not trigger. You should mark the primary email field as 'Required' in its properties to prevent empty submissions.




