How to find whether a particular string has unicode characters (esp. Double Byte characters)

后端 未结 6 864
我在风中等你
我在风中等你 2020-12-08 13:55

To be more precise, I need to know whether (and if possible, how) I can find whether a given string has double byte characters or not. Basically, I need to open a pop-up to

6条回答
  •  抹茶落季
    2020-12-08 14:27

    I used mikesamuel answer on this one. However I noticed perhaps because of this form that there should only be one escape slash before the u, e.g. \u and not \\u to make this work correctly.

    function containsNonLatinCodepoints(s) {
        return /[^\u0000-\u00ff]/.test(s);
    }
    

    Works for me :)

提交回复
热议问题