1. Text box can only enter numeric code ( Decimal point cannot be entered ): 

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

 

2. Only numbers can be entered , Can input decimal point . ( method 1) 

<input οnkeyup="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='';}"> 

 

3. Number and decimal point method 2  

<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 , Cannot enter Chinese  

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

 

6. Only numbers and English can be entered  

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

 

7. There can be no more than two decimal places ( number , Chinese can be input ), Letters and 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 be no more than two decimal places ( number , letter , Chinese can be input ), You can enter operation symbols : 

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

 

 

 

call onkeypress Event implementation Limit text boxes to numbers and decimal points only ( And only input 1 second ) 

function KeyPress(objTR) 



   var txtval = objTR.value; 

   var key = event.keyCode; 

   if((key <48 || key >57)&&key !=46) 

   { 

         event.keyCode = 0; 

   } 

   else 

   { 

         if(key == 46) 

         { 

               if(txtval.indexOf(".") != -1 || txtval.length == 0) 

                     event.keyCode = 0; 

         } 

   } 

 

}

 

Technology
©2019-2020 Toolsou All rights reserved,
java Four functional interfaces ( a key , simple )os Simple use of module HashMap Explain in detail html Writing about cherry trees , Writing about cherry trees It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) computer network --- Basic concepts of computer network ( agreement , system ) Some East 14 Pay change 16 salary , Sincerity or routine ? Browser kernel ( understand )