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]/))
I need to do the same thing not for the document but for a single variable.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
.matchis a string method. You can apply it to anything that contains string. And, of course, to arbitrary variable.In case you have something that is not string, most objects define
.toString()method that converts its content to some reasonable stringified form. When you retrieve selection from page, you get selection object. Convert it to string and then usematchon it:sel.toString().match(...).