How can I check if variable contains Chinese/Japanese characters?

前端 未结 2 618
既然无缘
既然无缘 2020-12-29 15:34

How do I check if a variable contains Chinese or Japanese characters? I know that this line works:

if (document.body.innerText.match(/[\\u3400-\\u9FBF]/))
         


        
2条回答
  •  猫巷女王i
    2020-12-29 15:39

    afaik you can to the same with a variable... document.body.innerText just returns the text of the body. Therefore you can just do

    myvar.match(...)
    

    Here's an example: http://snipplr.com/view/15357/

提交回复
热议问题