How to Mask an SSN Except for the Last Four Digits in Adobe Acrobat PDF
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.

- 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.
Ensure you have access to the form field editing tools and JavaScript properties in your PDF editor before applying the formatting script.
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.
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.
Right-click the visible display field, select 'Properties' from the context menu, and navigate to the 'Format' tab.
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, '*');
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.

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. Open Your PDF: Launch WPS Office and open the PDF document containing the sensitive information.
- 2. Access Security Tools: Navigate to the 'Protect' tab on the top ribbon to access encryption and redaction options.
- 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. Save the Secure File: Apply the redactions and save the document to finalize the removal of the sensitive data.

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.




