Home  >  Article  >  Web Front-end  >  How to limit the text box to only Chinese input in js_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 15:45:521193browse

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>

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

Statement:
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