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

How to limit the text box to only Chinese input in js_javascript skills

WBOY
Release: 2016-05-16 15:45:52
Original
1212 people have browsed it

The example in this article describes how to use js to limit the text box to only Chinese input. Share it with everyone for your reference. The details are as follows:

Allow the text box to only enter Chinese methods and codes. If you accidentally enter English, it will automatically go back and clear your input. It will continue until you enter Chinese. It is very interesting and practical. , which can be used to improve the accuracy of input when registering some information.

The operation effect is as shown below:

The specific code is as follows:

<html>
<head>
<title>让一个文本框只能输入汉字的方法</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">试着在文本框里分别输入汉字和英文字符试试?
</body>
</html>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

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