The idea of judging whether there is Chinese is that there can be any characters before and after, as long as it matches this problem, this problem can be solved, and the code is simple and the idea is clear
The first method of js to judge whether there is Chinese
]
js to determine whether The second code with Chinese
is a super simple method
The code is as follows:
if (escape(str).indexOf("%u") < 0)
{
//String str contains Chinese characters
}
How does it work? It is escape to encode the string. Character values greater than 255 are stored in %u**** format, and character values greater than 255 happen to be non-English characters (generally Chinese characters, non-Chinese characters can also be considered as Chinese characters) .
IndexOf is used to determine whether a certain substring exists in the string. If not found, it returns -1.
js check if all are in Chinese