Get the App
SLTechnology News&Howtos  ›  Development  › 

How to control that javascript cannot input Chinese characters

Shulou Source: shulou.com Published: 2022-06-02 02:45:51 10月05日 Update

Editor to share with you how javascript can not input Chinese characters, I hope you can learn something after reading this article, let's discuss it together!

Methods: 1, using regular expression to judge whether it is Chinese character and forbidding input, the regular expression grammar of matching Chinese character is "/ [\ u4E00 -\ u9FA5] / g"; 2, using Unicode character range control can not input Chinese characters, the coding of Chinese characters is greater than 255, so as long as the coding is greater than 255Chinese characters.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

How to control that javascript cannot input Chinese characters

1. Judging by regular expressions, it is very simple and can be implemented in two codes, as follows:

2. Judge by Unicode character range

In Unicode characters, because the coding of Chinese characters is greater than 255, as long as the coding is greater than 255Chinese characters, the code is as follows:

3. When you want to use the above two methods, it is very simple and can be called directly. Specific examples are as follows:

After reading this article, I believe you have a certain understanding of "how to control javascript not to input Chinese characters". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Chinese characters input control coding characters regularities expressions codes methods articles scope two finished examples tutorials more environment computer knowledge system Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Redmi macOS MariaDB NVidia