Home > Web Front-end > Front-end Q&A > How to control the inability to input Chinese characters in javascript

How to control the inability to input Chinese characters in javascript

WBOY
Release: 2022-01-12 15:48:45
Original
3635 people have browsed it

Method: 1. Use regular expressions to determine whether they are Chinese characters and prohibit input. The regular expression syntax for matching Chinese characters is "/[\u4E00-\u9FA5]/g"; 2. Use Unicode character range control You cannot enter Chinese characters. The encoding of Chinese characters is greater than 255, so as long as the encoding is greater than 255, they are all Chinese characters.

How to control the inability to input Chinese characters in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

How to control the inability to input Chinese characters in javascript

1. Use regular expressions to judge. It is very simple and can be achieved with two codes. The details are as follows :

How to control the inability to input Chinese characters in javascript

2. Use Unicode character range to determine

Among Unicode characters, because the encoding of Chinese characters is greater than 255, so as long as the encoding is greater than 255 is a Chinese character, the code is as follows:

How to control the inability to input Chinese characters in javascript

3. When you want to use the above two methods, it is very simple, just call it directly. The specific usage examples are as follows:

How to control the inability to input Chinese characters in javascript

【Related recommendations: javascript learning tutorial

The above is the detailed content of How to control the inability to input Chinese characters in javascript. For more information, please follow other related articles on the PHP Chinese website!

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