js 제어 텍스트 상자 입력 숫자 와 소수점 등

 1 1.           (        )
 2 <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
 3 
 4 2.      ,     .
 5 <input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
 6 <input name=txt1 onchange="if(/\D/.test(this.value)){alert('      ');this.value='';}">
 7 
 8 3.         
 9 <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}">
10 
11 4.         
12 <input onkeyup="value=value.replace(/[\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))" maxlength=10 name="Numbers">
13 
14 5.           ,      
15 <input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
16 
17 6.         <font color="Red">chun</font>
18 <input onKeyUp="value=value.replace(/[^\d|chun]/g,'')">
19 
20 7.           (  ,      ),           :
21 <input onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false">
22 
23 8.           (  ,  ,      ),        :
24 <input onkeyup="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')">
25 
26               
27 
28 onkeypress="return event.keyCode>=4&&event.keyCode<=57"

좋은 웹페이지 즐겨찾기