PDF Security & Access Issues

How to Mask an SSN Except for the Last Four Digits in Adobe Acrobat PDF

Steven ParkerSteven Parker Oct 28, 2026 868 views

Question details

The user needs to format a Social Security Number (SSN) in a PDF so that it displays in the format ***-**-####, keeping only the last four digits visible while preserving the original input value.

How to Mask an SSN Except for the Last Four Digits in Acrobat PDF
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating or modifying a PDF form where sensitive SSN data needs to be visually masked for privacy on the document interface.
Observed behavior
The form field should visually replace the first five digits of the SSN with asterisks but maintain the actual data in the background for calculations or backend processing.
Before you start

Ensure you have access to the form field editing tools and JavaScript properties in your PDF editor before applying the formatting script.

Solution 1Recommended

Use a Custom Format Script on a Display Field

Apply a custom JavaScript format to a separate display field to visually mask the SSN without permanently altering or losing the original numeric value.

It is best practice to use a separate display field whenever the original SSN must remain available for calculations or backend processing. This ensures the raw data is kept intact while only the masked version is shown to the user.

1
Create Separate Fields

Add two form fields to your PDF: a hidden text field for storing the actual SSN, and a visible text field designated for display purposes.

2
Open Field Properties

Right-click the visible display field, select 'Properties' from the context menu, and navigate to the 'Format' tab.

3
Add the Formatting Script

Select 'Custom' from the format category dropdown. Click 'Edit' next to the 'Custom Format Script' section and input the following code: var value = event.valueAsString; event.value = value.replace(/\d(?=\d{4})/g, '*');

4
Test the Field

Save your changes and test the field by typing both nine-digit strings and hyphenated SSN values to verify that only the last four digits remain visible.

Use a Custom Format Script on a Display Field
Data Security Warning: Visual masking alone is not true data security. The original numbers are still present in the document. Ensure you protect the PDF with proper encryption or use redaction tools if the document will be shared publicly.
Secure PDF Editing

Protect and Redact Sensitive Information with WPS PDF

If you need a straightforward way to securely edit PDF forms or permanently redact sensitive information like SSNs, WPS Office offers a comprehensive set of PDF security and editing tools that are highly compatible and easy to use.

  1. 1. Open Your PDF: Launch WPS Office and open the PDF document containing the sensitive information.
  2. 2. Access Security Tools: Navigate to the 'Protect' tab on the top ribbon to access encryption and redaction options.
  3. 3. Redact Sensitive Data: Select the 'Redact' tool to permanently black out or mask SSNs and other confidential text so it cannot be recovered.
  4. 4. Save the Secure File: Apply the redactions and save the document to finalize the removal of the sensitive data.
Permanently redact sensitive text to prevent data leaksHigh format compatibility with Adobe Acrobat PDF filesEasily apply document passwords and permission restrictionsLightweight, intuitive interface for fast PDF processing
microsoft office alternative - wps office

Frequently Asked Questions

Does visual masking with asterisks secure the SSN data?

No. Using a format script to display asterisks only changes how the data looks on the screen. The underlying data remains in the PDF structure. For complete security, you should use PDF encryption or permanent redaction tools.

Why should I use a separate display field for the masked SSN?

If you mask the original input field directly, any formulas or backend scripts trying to process the SSN will read the asterisks instead of the numbers. A separate display field preserves the raw data in a hidden field for accurate processing.

Will this JavaScript code handle SSNs with hyphens?

Yes, the provided regular expression targets only digits that are followed by at least four other digits. It will mask the numbers but leave hyphens and the final four digits untouched.