How to Use JavaScript to Allow Hiragana-Only Input in a PDF Form
Question details
The user needs to restrict a PDF form field so that it only accepts Japanese Hiragana characters.

- 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.
Ensure you have access to a professional PDF editor with form creation and custom JavaScript execution capabilities, such as WPS PDF or Adobe Acrobat.
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.
Right-click the target text field in form editing mode and select Properties.
In the Properties dialog box, click on the 'Validate' tab at the top.
Select the option 'Run custom validation script' and click the 'Edit' button.
Type the following script: if (!/^[\u3040-\u309F]*$/.test(event.value)) { app.alert('Please enter hiragana characters only.'); event.rc = false; }
Click OK to save the script, close the properties window, and test the form by entering a mix of Hiragana, Kanji, and Latin characters.

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. Open your PDF: Launch WPS PDF and open the document you wish to turn into an interactive form.
- 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. Access Properties: Double-click the newly created text field to open its Properties panel.
- 4. Apply Validation Script: Switch to the 'Validate' section, choose to run a custom validation script, and paste your Hiragana regex code.

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.




