'Not allow Korean character(Hangul) for input text
I want to allow typing Latin Characters but I don't want user can type Korean Hangul characters. Please help me answer. Thank you in advance.
Solution 1:[1]
Based on this article, https://en.wikipedia.org/wiki/Korean_language_and_computers
You would want to do something like this (untested):
$(document).on('keypress', 'input', function (e) {
var key = event.which || event.keyCode;
// Hangul Syllables
if (key >= 0xAC00 && key <= 0xD7A3) {
e.preventDefault();
}
// Hangul Jamo
if (key >= 0x1100 && key <= 0x11FF) {
e.preventDefault();
}
// Hangul Compatibility Jamo
if (key >= 0x3130 && key <= 0x318F) {
e.preventDefault();
}
// Hangul Jamo Extended-A
if (key >= 0xA960 && key <= 0xA97F) {
e.preventDefault();
}
// Hangul Jamo Extended-B
if (key >= 0xD7B0 && key <= 0xD7FF) {
e.preventDefault();
}
});
However, this would not stop anyone from copying/pasting Hangul characters into the input field, you would need to find something separate for that.
A more simplified way is to use form validation (this is a more simplified approach):
<input type="text" pattern="[^?-?]+">
What you should do is instead be testing for the characters on the server side and returning a form error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | bashaus |