PDF Editing Issues

How to Validate and Restrict Email Address Input in PDF Forms Using JavaScript

Rana GarciaRana Garcia Nov 24, 2026 869 views

Question details

The user needs to create a dynamic validation script in a PDF form that checks for a valid email format, alerts the user if it is invalid, and forces a correction by outright rejecting the bad input.

How to Validate and Restrict Email Address Input in PDF Forms Using JavaScript
Product
Adobe Acrobat / PDF Editors
Device & OS
not provided
Scenario
Creating interactive PDF forms that require respondents to submit valid email addresses.
Observed behavior
The form field needs to actively reject invalid email formatting and prevent saving the bad data, rather than just delivering a warning that users can ignore.
Before you start

Ensure your PDF editing software supports JavaScript form field validation and that your interactive PDF already contains a designated text field for the email address.

Solution 1Recommended

Implement Custom Validation Script for Email Fields

Use a Regular Expression (Regex) within the form field's Custom Validation script to evaluate the input format and use event.rc to explicitly reject bad data.

Standard format checks sometimes only warn users but still allow incorrect data to be passed through. By using custom JavaScript validation, you have full control over the input. Setting the return code (event.rc) to false forces the PDF viewer to reject the input string entirely, effectively trapping the user in the field until they provide a properly formatted email or clear the field.

1
Open PDF in form editing mode

Launch your PDF editor and enter the form preparation or editing mode to reveal the interactive fields.

2
Access text field properties

Right-click the text field you intend to use for the email address and select 'Properties' from the context menu.

3
Navigate to the Validate tab

In the Properties dialog box, click on the 'Validate' tab to view validation options.

4
Add custom validation script

Select the radio button for 'Run custom validation script' and click the 'Edit' button to open the JavaScript editor.

5
Enter the JavaScript regex code

Paste your email validation script. For example: var emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; if (event.value && !emailRegex.test(event.value)) { app.alert('Please enter a valid email address.'); event.rc = false; }. This strictly tests the input and uses event.rc = false to reject invalid attempts.

Implement Custom Validation Script for Email Fields
Ensure Correct Syntax: Be careful with the regular expression syntax. Testing your regex thoroughly ensures you do not accidentally block valid, albeit complex, email addresses.

Create and Manage Interactive PDF Forms with WPS Office

WPS PDF provides comprehensive tools to create, edit, and fill out interactive PDF forms quickly. Whether you need text fields, checkboxes, or dropdowns, WPS PDF handles form management efficiently and ensures high compatibility across platforms without unnecessary complexity.

  1. 1. Open WPS PDF: Launch WPS Office and open your PDF document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab in the top ribbon to view all interactive form controls.
  3. 3. Add Text Fields: Click 'Text Field' and draw the box where you want users to input their information, like an email address.
  4. 4. Modify Properties: Double-click the new field to customize its name, appearance, and acceptable formatting options.
Easily add and edit PDF form fields including text, checkboxes, and buttonsHigh compatibility with standard PDF viewing and editing formatsLightweight application that opens large PDFs in secondsFree built-in features to read, annotate, and sign PDFs electronically
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF form still accept invalid emails after showing the alert?

If your validation script only triggers an alert using app.alert, the invalid email will still be saved. You must include 'event.rc = false;' in your script to explicitly tell the PDF viewer to reject the user's input and keep the field active for correction.

Can I validate other data types like phone numbers in PDF forms using this method?

Yes, using similar Custom Validation scripts, you can write specific regular expressions to evaluate phone numbers, zip codes, or custom ID formats, deploying 'event.rc = false;' whenever the formats do not match.

Will JavaScript validation work on all mobile PDF viewers?

Support for JavaScript in PDF forms varies significantly across mobile apps. While robust applications like WPS Office and Adobe Acrobat typically handle JS seamlessly, default system viewers on mobile devices might ignore complex validation scripts.