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

js restricts the input content of the text box code sharing (category 3)_javascript skills

WBOY
Release: 2016-05-16 15:43:56
Original
1194 people have browsed it

The JavaScript restriction text box input content code shared with you is as follows

<style type="text/css">
<!--
.STYLE1 {
 color: #0099FF;
 font-weight: bold;
 font-size: x-large;
}
-->
</style>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p align="center" class="STYLE1">亲,试试效果吧!</p>
<p align="center"><strong>请输入数字或字母</strong>:
 <input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
</p>
<p align="center"><strong>请输入数字,只能输入数字哦</strong>:
 <input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
</p>
<p align="center"><strong>请输入汉字,只能输入汉字哦</strong>:
 <input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
</p>
Copy after login

Operation rendering:

Let me add some more for you:

There can only be up to two digits after the decimal point (both numbers and Chinese characters can be entered). Letters and arithmetic symbols cannot be entered:

<input onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || //./d/d$/.test(value))event.returnValue=false">
Copy after login

Only numeric codes can be entered in the text box (decimal points cannot be entered either)

<input onkeyup="this.value=this.value.replace(//D/g,'')" onafterpaste="this.value=this.value.replace(//D/g,'')">
Copy after login

In fact, you can also restrict other content, such as only letters. You can try some other things.

The above is the JavaScript restriction text box input content code shared with everyone

Related labels:
js
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