input can only input numbers, letters, Chinese characters, etc.

1. The text box can only enter numeric codes (can not enter decimal points)
<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">

2. Only numbers can be entered, and decimal points can be entered.
<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
<input name="txt1" onchange="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}">

3. Numbers and decimal point method 2
<input type="text" t_value="" o_value="" onkeypress="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" onkeyup="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" onblur="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 input
<input onkeyup="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 input, not Chinese
<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">

6. Only numbers and English can be entered <font color="Red">chun</font>
<input onkeyup="value=value.replace(/[^\d|chun]/g,'')">

7. There can only be up to two digits after the decimal point (numbers and Chinese can be entered), letters and operation symbols cannot be entered:
<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 digits after the decimal point (numbers, letters, and Chinese can be entered), and operators can enter:
<input onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')">

9. Enter Chinese:
<input type="text" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">  

10. Enter numbers:  
<input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')">  

11. Enter English:  
<input type="text" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">  

12. Three in one  
<input onkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')">  

13. Enter only numbers and letters  
<input class="input" maxlength="12" size="15" name="username" id="username" onkeyup="value=value.replace(/[\W]/g,'')">

14. Except for English punctuation, I think that everyone else can use Chinese, English letters, numbers, and Chinese punctuation
<input type="text" onkeyup="this.value=this.value.replace(/^[^!@#$%^&*()-=+]/g,'')">

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326173847&siteId=291194637