Limit the input input box to only input pure numbers
1, onkeyup = "value=value.replace(/[^\d]/g,'')"
Using the onkeyup event, there is a bug, that is, in the state of the Chinese input method, enter the letter directly after entering the Chinese character
2、onchange = "value=value.replace(/[^\d]/g,'')"
Using the onchange event, after entering the content, the result will only be obtained when the input loses focus, and it cannot respond immediately when entering
3、oninput = "value=value.replace(/[^\d]/g,'')"
Using the oninput event,
Enter uppercase and lowercase letters, numbers, and underscores:
<input type="text" onkeyup="this.value=this.value.replace(/[^\w_]/g,'');">
Enter lowercase letters, numbers, underscore:
<input type="text" onkeyup="this.value=this.value.replace(/[^a-z0-9_]/g,'');">
Enter numbers and points
<input type="text" onkeyup="value=value.replace(/[^\d.]/g,'')">
Input Chinese:
<input type="text" οnkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">
输入数字:
<input type="text" οnkeyup="this.value=this.value.replace(/\D/g,'')">
输入英文:
<input type="text" οnkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">
Input Chinese, numbers, English:
<input οnkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')">
Enter numbers and letters:
<input onKeyUp="value=value.replace(/[\W]/g,'')">
Except English punctuation marks, others can be Chinese, English letters, numbers, Chinese punctuation
<input type="text" οnkeyup="this.value=this.value.replace(/^[^!@#$%^ &*()-=+]/g,'')">
Only numeric codes can be entered (decimal points cannot be entered)
<input Onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/ \D/g,'')">
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 οnchange="if(/\D/.test(this.value)){alert('only numbers can be entered');this.value='';}">
数字和小数点方法二
<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}">
Only letters and Chinese characters can be
entered (/[\d]/g,''))" maxlength=10 name="Numbers">
Only English letters and numbers can be entered, Chinese cannot be entered
<input οnkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
Only numbers and English can be entered
<input onKeyUp="value=value.replace(/[^\d|chun]/g,'')">
There can only be a maximum of two digits after the decimal point (numbers and Chinese can be input), and letters and operation symbols cannot be input:
<input onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode! =46 || /\.\d\d$/.test(value))event.returnValue=false">
There can only be a maximum of two digits after the decimal point (numbers, letters, and Chinese can be entered), and you can enter operation symbols:
<input Onkeyup="this.value=this.value.replace(/^(\-)*(\d+) \.(\d\d).*$/,'$1$2.$3')">