Title: Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese) · Issue #3978 · javascript-tutorial/en.javascript.info · GitHub
Open Graph Title: Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese) · Issue #3978 · javascript-tutorial/en.javascript.info
X Title: Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese) · Issue #3978 · javascript-tutorial/en.javascript.info
Description: Article Keyboard: keydown and keyup — the "Default actions" section, phone-number filter example: Problem The example (and the surrounding text) i...
Open Graph Description: Article Keyboard: keydown and keyup — the "Default actions" section, phone-number filter example: Problem ...
X Description: Article Keyboard: keydown and keyup — the "Default actions" section, phone-number filter example: <input onkeydown="return checkPhoneKey(event.key)" placeholder="Phone, ...
Opengraph URL: https://github.com/javascript-tutorial/en.javascript.info/issues/3978
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Keyboard events: keydown filtering example can't block IME-composed input (Korean/Japanese/Chinese)","articleBody":"## Article\n\n[Keyboard: keydown and keyup](https://javascript.info/keyboard-events) — the \"Default actions\" section, phone-number filter example:\n\n```html\n\u003cinput onkeydown=\"return checkPhoneKey(event.key)\" placeholder=\"Phone, please\" type=\"tel\"\u003e\n```\n\n## Problem\n\nThe example (and the surrounding text) implies that returning `false` from `keydown` reliably prevents unwanted characters from being entered. That holds for direct (Latin) keyboard input, but not for languages typed through an IME (Input Method Editor), such as Korean, Japanese and Chinese.\n\nWith an IME active:\n\n- `keydown` fires with `event.key == \"Process\"` (and `keyCode` 229), not the actual character.\n- More importantly, calling `preventDefault()` / returning `false` on that `keydown` does **not** cancel the text insertion, because the character is produced by the IME composition, not by the key's default action.\n\nAs a result, Korean/Japanese/Chinese characters pass straight through the filter and appear in the field. This was reported by a Korean reader of the Korean translation (ko.javascript.info), and is easy to reproduce by switching to a Korean IME and typing into the demo.\n\n## Suggestion\n\nAdd a short note after the example, along these lines:\n\n\u003e Please note: this filter only works for direct keyboard input. Text composed via an IME (used for languages such as Korean, Japanese or Chinese) is inserted by the input method, not by the key's default action, so it can't be blocked in `keydown`. That's one more reason why, for tracking or validating what actually gets into the field, the `input` event is a better choice.\n\nThis ties in nicely with the introduction of the article, which already recommends the `input` event for tracking input from any source.\n\nHappy to send a PR if the note sounds good.\n","author":{"url":"https://github.com/Violet-Bora-Lee","@type":"Person","name":"Violet-Bora-Lee"},"datePublished":"2026-07-18T18:27:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/3978/en.javascript.info/issues/3978"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:874ed3ef-89ad-ec1d-7a46-640af4f58ee6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 965C:1DD66:561DEA:7A444D:6A62FF71 |
| html-safe-nonce | 8aeb97287c9cb43c3060459c865a48b1f9efff5c56fca13f463807752ce11ced |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjVDOjFERDY2OjU2MURFQTo3QTQ0NEQ6NkE2MkZGNzEiLCJ2aXNpdG9yX2lkIjoiMzUxNDU3OTg5MTk0OTYwMDYyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c9617710cef99ae2252f782d7e4268a5dfd313fb174010f182a1863b469861d7 |
| hovercard-subject-tag | issue:4919522579 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/javascript-tutorial/en.javascript.info/3978/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04b0ccaf3b51945a2ad78cbf31f8cbb16b3dccf9450acd8395989be17c7d492f/javascript-tutorial/en.javascript.info/issues/3978 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04b0ccaf3b51945a2ad78cbf31f8cbb16b3dccf9450acd8395989be17c7d492f/javascript-tutorial/en.javascript.info/issues/3978 |
| og:image:alt | Article Keyboard: keydown and keyup — the "Default actions" section, phone-number filter example: Problem ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Violet-Bora-Lee |
| hostname | github.com |
| expected-hostname | github.com |
| None | 14517cd57568049be7ed25bfe9708f10d1e36b7254adfd920dfb9d44bcc71c41 |
| turbo-cache-control | no-preview |
| go-import | github.com/javascript-tutorial/en.javascript.info git https://github.com/javascript-tutorial/en.javascript.info.git |
| octolytics-dimension-user_id | 49552305 |
| octolytics-dimension-user_login | javascript-tutorial |
| octolytics-dimension-repository_id | 93253246 |
| octolytics-dimension-repository_nwo | javascript-tutorial/en.javascript.info |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 93253246 |
| octolytics-dimension-repository_network_root_nwo | javascript-tutorial/en.javascript.info |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b2ed33e3827bc186c45c037f9274b5493aaca4c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width