PDF Editing Issues

How to Use JavaScript to Allow Hiragana-Only Input in a PDF Form

Nimra MalikNimra Malik Nov 3, 2026 868 views

Question details

The user needs to restrict a PDF form field so that it only accepts Japanese Hiragana characters.

How to Use JavaScript to Allow Hiragana-Only Input in a PDF Form
Product
PDF Editors
Device & OS
not provided
Scenario
Creating a Japanese kanji reading test where respondents must provide their answers exclusively in Hiragana.
Observed behavior
The form field needs to reject Kanji, Katakana, and Romaji inputs, displaying an alert message when invalid characters are entered.
Before you start

Ensure you have access to a professional PDF editor with form creation and custom JavaScript execution capabilities, such as WPS PDF or Adobe Acrobat.

Solution 1Recommended

Apply a Custom JavaScript Validation Regex

Add a validation script to the form field properties that checks the input against the Hiragana Unicode block range.

You can restrict input by testing the user's keystrokes against a regular expression. The Unicode range for standard Hiragana characters is U+3040 through U+309F.

1
Open Field Properties

Right-click the target text field in form editing mode and select Properties.

2
Navigate to the Validate Tab

In the Properties dialog box, click on the 'Validate' tab at the top.

3
Enter Custom Validation Script

Select the option 'Run custom validation script' and click the 'Edit' button.

4
Input the JavaScript Code

Type the following script: if (!/^[\u3040-\u309F]*$/.test(event.value)) { app.alert('Please enter hiragana characters only.'); event.rc = false; }

5
Save and Test

Click OK to save the script, close the properties window, and test the form by entering a mix of Hiragana, Kanji, and Latin characters.

Apply a Custom JavaScript Validation Regex
Allowing Blank Inputs: The asterisk (*) in the regular expression ensures that the script accepts empty fields without triggering the error message. Change the asterisk to a plus sign (+) if a blank submission should also be blocked.
Edit PDF Forms Easily

Create and Validate PDF Forms Using WPS PDF

WPS PDF provides robust, user-friendly tools for creating interactive forms, allowing you to quickly insert text fields, apply format rules, and run custom JavaScript validations without complex settings.

  1. 1. Open your PDF: Launch WPS PDF and open the document you wish to turn into an interactive form.
  2. 2. Insert a Text Field: Go to the 'Form' tab on the ribbon and click 'Text Field' to draw an input box on your page.
  3. 3. Access Properties: Double-click the newly created text field to open its Properties panel.
  4. 4. Apply Validation Script: Switch to the 'Validate' section, choose to run a custom validation script, and paste your Hiragana regex code.
Easily insert and customize interactive text fields, checkboxes, and dropdowns.Fully compatible with Adobe Acrobat PDF form formats and JavaScript actions.Lightweight interface designed for quick and intuitive document editing.Apply custom validations to ensure accurate data collection in tests and surveys.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use JavaScript to restrict Katakana-only input instead?

Yes. You simply need to replace the Unicode range in the regular expression. To validate Katakana characters, use /^[\u30A0-\u30FF]*$/ in your test condition.

Why is the script not working when users view the PDF in a web browser?

Many default web browser PDF viewers (like those built into Chrome or Edge) have limited or completely disabled JavaScript support for security reasons. Users should open the form in dedicated PDF software like WPS PDF to ensure scripts run properly.

How do I prevent users from copy-pasting Kanji into the text field?

The custom validation script automatically evaluates the field value when it commits, such as when the user clicks outside the box or presses Enter. Even if Kanji is pasted, the script will trigger the alert and reject the input.