0

I want to write numbers only So I did this

$('#myId').on('keydown', '#myInput',function(event){
    var charCode = (event.which) ? event.which : event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            event.preventDefault();
    }
    //...
})

This code works in English very well. But this code doesn't work in Hangul(Korean). The text is written before the event occurs.

Anyone help me

taeun
  • 95
  • 1
  • 6
  • You can try adding: – PHP Geek Jan 05 '18 at 04:14
  • 1
    Rather than which/keyCode, consider using a regular expression to test what the user actually entered. Are any Korean characters within the ASCII character range? Likely you need to use code points for the related characters, e.g. `/\u1100/.test('ᄀ')` returns `true`. See [*HANGUL IN UNICODE*](http://www.programminginkorean.com/programming/hangul-in-unicode/), also [*Javascript + Unicode regexes*](https://stackoverflow.com/questions/280712/javascript-unicode-regexes). – RobG Jan 05 '18 at 04:22
  • @RobG I don't understand.. But the obvious thing is that after the text has already been written, it goes into the event function. – taeun Jan 05 '18 at 06:18
  • For example, to test if a string contains only the digits 0 to 9 or Hangul digits ᄀ to ᄉ, you can use the expression `/^[\u1100-\u1109,0-9]*$/.test(string)`, where `\u1100` is the unicode code point for ᄀ (0) and \u1109 the code point for ᄉ (9) and the `-` represents everything in between. Please note that I know nothing about Korean so may be using the wrong character set, but hopefully you get the idea. – RobG Jan 05 '18 at 06:46

0 Answers0