当前位置:网站首页>Restrict input type (multiple methods)
Restrict input type (multiple methods)
2022-06-22 08:01:00 【xiaoke815】
1. Only Chinese characters can be input and pasted
<input οnkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"><br/>
3. Only numbers can be entered and pasted
<input οnkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" /><br/>
4. Digital script
<input οnkeyup="if(/\D/.test(this.value)){alert(' You can only enter Numbers ');this.value='';}"><br/>
5. You can only input numbers and English
<input οnkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"><br/>
6. Simple forbid to input Chinese characters
<input style="ime-mode:disabled"> Input method does not convert , But it can be pasted <br/>
7. Enter numbers and decimal points
<input οnkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" /><br/>
8. Only numbers and "-", For example, when inputting time, you can use
<input οnkeyup="value=value.replace(/[^\w&=]|_/ig,'')" οnblur="value=value.replace(/[^\w&-]|_/ig,'')" />
JS control input Input character limit
ENTER Key to move the cursor to the next input box
The code is as follows :
<input οnkeydοwn="if(event.keyCode==13)event.keyCode=9" > Only in Chinese
<input οnkeyup="value=value.replace(/[ -~]/g,'')" οnkeydοwn="if(event.keyCode==13)event.keyCode=9"> Masked input method <input style="ime-mode:disabled" οnkeydοwn="if(event.keyCode==13)event.keyCode=9"> Only English and numbers can be entered
<input οnkeyup="value=value.replace(/[/W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))" οnkeydοwn="if(event.keyCode==13)event.keyCode=9"> It's just numbers
<input οnkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))">
Can only display , Do not modify
The code is as follows :
<input readonly value=" Can only display , Do not modify "> Only numbers can be entered , Determine the value of the key
<script language=javascript>
function onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)||(event.keyCode==8)))
event.returnValue=false;
}
</script>
<input οnkeydοwn="onlyNum();">
1. Only numeric codes can be entered in the text box ( You can't enter a decimal point )
<input οnkeyup="this.value=this.value.replace(//D/g,'')" onafterpaste="this.value=this.value.replace(//D/g,'')">
2. You can only enter Numbers , Can enter decimal point .
<input οnkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
<input name=txt1 οnchange="if(//D/.test(this.value)){alert(' You can only enter Numbers ');this.value='';}">
3. Number and decimal point method 2
The code is as follows :
<input type=text t_value="" o_value="" οnkeypress="if(!this.value.match(/^[/+/-]?/d*?/.?/d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[/+/-]?/d+(?:/./d+)?)?$/))this.o_value=this.value" οnkeyup="if(!this.value.match(/^[/+/-]?/d*?/.?/d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[/+/-]?/d+(?:/./d+)?)?$/))this.o_value=this.value" οnblur="if(!this.value.match(/^(?:[/+/-]?/d+(?:/./d+)?|/./d*?)?$/))this.value=this.o_value;else{if(this.value.match(/^/./d+$/))this.value=0+this.value;if(this.value.match(/^/.$/))this.value=0;this.o_value=this.value}">
4. Only letters and Chinese characters can be entered
<input οnkeyup="value=value.replace(/[/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[/d]/g,''))" maxlength=10 name="Numbers">
5. Only English letters and numbers can be entered , Can't input Chinese
<input οnkeyup="value=value.replace(/[^/w/.//]/ig,'')">
6. You can only input numbers and English
<font color="Red">chun</font>
<input onKeyUp="value=value.replace(/[^/d|chun]/g,'')">
7. There can only be up to two decimal places after the decimal point ( Numbers , Chinese can be input ), You can't enter letters and symbols :<input onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || //./d/d$/.test(value))event.returnValue=false">8. There can only be up to two decimal places after the decimal point ( Numbers , Letter , Chinese can be input ), You can enter the operation symbol :
<input οnkeyup="this.value=this.value.replace(/^(/-)*(/d+)/.(/d/d).*$/,'$1$2.$3')">
It can only be numbers, decimal points and addition, subtraction and multiplication
9. You can only enter Numbers 、 decimal point 、 negative
The code is as follows :
<input name="input" type="text" οnkeyup="JHshNumberText(this)" id="title">
<script language="javascript" type="text/javascript">function JHshNumberText(a)
{
var fa="";
if(a.value.substring(0,1)=="-")
fa="-";
var str=(a.value.replace(/[^0-9.]/g,'')).replace(/[.][0-9]*[.]/, '.');
if (str.substring(0,1)==".")
str="0"+str;
a.value=fa+str;
}
</script>
1. The dotted box when the Cancel button is pressed , stay input Add attribute values to hideFocus perhaps HideFocus=true
<input type="submit" value=" Submit " hidefocus="true" />
2. Read only text box content , stay input Add attribute values to readonly
<input type="text" readonly />
3. To prevent it from being emptied TEXT file ( Can handle style Content as a class reference )
<input type="text" style="behavior:url(#default#savehistory);" />
4.ENTER Key to move the cursor to the next input box
<input type="text" οnkeydοwn="if(event.keyCode==13)event.keyCode=9" />
5. Chinese only ( There's a flash )
<input type="text" οnkeyup="value=value.replace(/[ -~]/g,'')" οnkeydοwn="if(event.keyCode==13)event.keyCode=9" />
6. Can only be a number ( There's a flash )
<input type="text" οnkeyup="value=value.replace(/[^/d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))" />
7. Can only be a number ( No flash )
<input type="text" style="ime-mode:disabled" οnkeydοwn="if(event.keyCode==13)event.keyCode=9" οnkeypress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false" />
8. Only English and numbers can be entered ( There's a flash )
<input type="text" οnkeyup="value=value.replace(/[/W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))" />
9. Masked input method
<input type="text" name="url" style="ime-mode:disabled" οnkeydοwn="if(event.keyCode==13)event.keyCode=9" />
10. Input only Numbers , decimal point , minus sign (-) character ( No flash )
<input οnkeypress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false" />
11. Only two decimal places can be entered , Three decimal places ( There's a flash )
<input type="text" maxlength="9" οnkeyup="if(value.match(/^/d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(//./d*/./g,'.')" οnkeypress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^/d{3}$/) || //./d{3}$/.test(value)) {event.returnValue=false}" />
边栏推荐
- Oracle gets the working day time between two dates
- QT QtableView的使用示例
- User defined pop-up use
- SVN 提交子文件夹问题
- Canvastotempfilepath of wechat
- Introduction to several mainstream and easy-to-use rich text editors (WYSIWYG common editors)
- 基于消息传递的并发编程(MPI)之异步收发
- How to handle root password forgetting in MySQL
- Windchill API drops
- Kotlin a simple Android program
猜你喜欢

Microsoft Remote Desktop 10.7.6 official

0基础自学stm32(野火)——什么是寄存器?

The applet uses the step bar vant steps in vant

充电宝的玄机

navicat如何查询已连接的数据库密码信息

mapTalks:基础操作与WMS/WMTS地图服务加载
![[songhongkang MySQL database] [advanced chapter] [07] MySQL storage engine](/img/47/62ad1e661e015438c40574f533d8f1.png)
[songhongkang MySQL database] [advanced chapter] [07] MySQL storage engine

对于mysql中数据为NULL引发的一些问题和思考

Use js to download the current image

Applet /vant UI to upload files
随机推荐
Scrollrect for tableview
模电实验——实验二 JFET共源极放大电路
ExcelToJson
Use js to download the current image
Example of using listagg in Oracle 11g (splicing the values of a field into a line, separated by commas)
Modular import and export collation in JS
How can MySQL query the records with the largest consumption amount of each user?
setneedsdisplay layoutifneeded setNeedsLayout
【宋红康 MySQL数据库 】【高级篇】【07】MySQL的存储引擎
JS to assign values to two objects with the same attributes
Node red sends wechat official account message (template message)
Cocoapods creates private libraries and publishes them
Excellent cases of data visualization
AutoCAD 2020.3 Chinese Version (old version)
Characteristics of industrial Internet
Symbolic processing of crash log
How Navicat queries the password information of the connected database
Wechat applets will directly open the parent element when the child element of flex:1 is too long (the text is too long)
Problems caused by canvas palette width and height and canvas width and height
CollectionViewCell