PDF Editing Issues

How to Compare and Validate Email Fields in a PDF Form

Amos GikundaAmos Gikunda Nov 3, 2026 869 views

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.

How to Compare and Validate Email Fields in a PDF Form
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Form Editing Mode

Open your PDF editor and navigate to the Form Editing or Prepare Form tools.

2
Access Field Properties

Right-click the 'confirmEmail' text field (the field where the user re-enters their email) and select Properties.

3
Add Custom Validation Script

Navigate to the Validate tab, select the option to run a custom JavaScript, and click Edit.

4
Enter the JavaScript Code

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!"); }

5
Test the Validation

Save the properties, exit form editing mode, and type different emails into the two fields to ensure the warning alert appears.

Use JavaScript to Compare Email Fields
Standard Format Validation: This script only compares the two fields. If you need to verify that the text actually looks like an email address (e.g., name@domain.com), you should add standard email-format validation to the primary 'email' field.
Manage PDF Forms Easily

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. 1. Download and Install: Download WPS Office for free and install it on your device.
  2. 2. Open Your Form: Launch WPS PDF and open your interactive PDF form.
  3. 3. Fill the Data: Navigate through the form fields; WPS PDF will automatically recognize interactive text fields, drop-downs, and checkboxes.
  4. 4. Save and Export: Once completed and validated, click Save or export the document to share it securely.
Seamlessly fill and interact with complex PDF formsHighly compatible with Adobe Acrobat PDF formats and interactive elementsLightweight application with a clean, user-friendly interfaceIncludes comprehensive tools for adding text, digital signatures, and stamps
microsoft office alternative - wps office

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.