Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  139] [ 6]  / answers: 1 / hits: 17406  / 12 Years ago, tue, june 26, 2012, 12:00:00

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.


More From » jquery

 Answers
36

.match is 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 use match on it: sel.toString().match(...).


[#84662] Monday, June 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leighrheac

Total Points: 313
Total Questions: 92
Total Answers: 94

Location: Papua New Guinea
Member since Thu, May 7, 2020
4 Years ago
;