Home > Web Front-end > JS Tutorial > body text

js determines whether there is a Chinese script_js determines Chinese method collection [original]_javascript skills

WBOY
Release: 2016-05-16 19:01:11
Original
1380 people have browsed it

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


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh it to execute
]
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
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template