Input box input limit

Only allow the input of numbers (integer: the decimal point cannot be input)
<input type="text" οnkeyup="value=value.replace(/[^\d]/g,'')" >
Allow input of decimals (two decimal places)
< input type="text" οnkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g,'$1')" >
Allow input of decimals (one decimal place)
<input type="text" οnkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,1})?). *$/g,'$1')">
cannot start with 0, and cannot enter decimals
<input type="text" οnkeyup="value=value.replace(/[^\d]/g,'').replace (/^0{1,}/g,'')">

Only numbers and decimal points can be input
<input type="text" οnkeyup="value=value.replace(/[^\-?\d.]/g,'')">

Enter uppercase and lowercase letters, numbers, and underscores:

<input type="text" οnkeyup="this.value=this.value.replace(/[^\w_]/g,'');">

Enter lowercase letters, numbers, Underscore:

<input type="text" οnkeyup="this.value=this.value.replace(/[^a-z0-9_]/g,'');">

input number and point

<input type="text "οnkeyup="value=value.replace(/[^\d.]/g,'')">

Input Chinese:   

<input type="text" οnkeyup="this.value=this.value.replace(/[ ^\u4e00-\u9fa5]/g,'')">  
  
Enter a number:   

<input type="text" οnkeyup="this.value=this.value.replace(/\D/g,'')">  

Enter English:   

<input type="text" οnkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">  
  
Enter Chinese, numbers, and English:   

<input οnkeyup="value=value.replace(/[^\w\u4E00-\u9FA5]/g,'')">  
 
Enter numbers and letters:

<input onKeyUp="value=value.replace(/[\W]/g,'')">  

Except for English punctuation, all other characters can be Chinese, English letters, numbers, and Chinese punctuation

<input type="text "οnkeyup="this.value=this.value.replace(/^[^!@#$%^&*()-=+]/g,'')">

Only enter the numeric code (not even the decimal point )

<input οnkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">

Only numbers can be input, and decimal points can be input.

<input οnkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">

<input name= txt1 οnchange="if(/\D/.test(this.value)){alert('Only enter numbers');this.value='';}">

Number and decimal point method two

<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}">

只能输入字母和汉字

<input οnkeyup="value=value.replace(/[\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))" maxlength=10 name="Numbers">

Only English letters and numbers can be input, Chinese cannot be input

<input οnkeyup="value=value.replace(/[^\w\.\/]/ig,'')">

Only numbers and English can be input

<input onKeyUp= "value=value.replace(/[^\d|chun]/g,'')">

There can only be at most two digits after the decimal point (digits and Chinese can be input), 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">decimal

point There can only be a maximum of two digits (numbers, letters, and Chinese can be input), and you can enter arithmetic symbols:

<input οnkeyup="this.value=this.value.replace(/^(\-)*(\d+)\ .(\d\d).*$/,'$1$2.$3')">

 

 

Guess you like

Origin blog.csdn.net/zheng_chang_wei/article/details/109777195