What is proper way to test if the input is Korean or Chinese using JavaScript?

前端 未结 1 324
谎友^
谎友^ 2021-01-22 18:24

My application was relying on this function to test if a string is Korean or not :

const isKoreanWord = (input) => {
  const match = input.match(/[\\u3131-\\u         


        
相关标签:
1条回答
  • 2021-01-22 18:49

    Here is the unicode range you need for Hangul (Taken from their wikipedia page).

    U+AC00–U+D7AF
    U+1100–U+11FF
    U+3130–U+318F
    U+A960–U+A97F
    U+D7B0–U+D7FF
    

    So your regex .match should look like this:

    const match = input.match(/[\uac00-\ud7af]|[\u1100-\u11ff]|[\u3130-\u318f]|[\ua960-\ua97f]|[\ud7b0-\ud7ff]/g);
    
    0 讨论(0)
提交回复
热议问题