HTML输入框---数字/中文/字母/组合

    

只能输入中文:

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

   

 只能输入英文:

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

    

只能输入数字(禁止输入小数点):

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

只能输入数字,可以输小数点:

方法一:<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='';}">  
方法三:<input onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d.]/g,'')" > 

  

只能输入数字和英文
<input onKeyUp="value=value.replace(/[^\d|chun]/g,'')"> 

  

只能输入字母和中文
<inputonkeyup="value=value.replace(/[\d]/g,'')"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))"maxlength=10 name="Numbers"> 

  

只能输入字母和数字
<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">  

  

禁止输入中文
<input type="text" oninput="this.value=this.value.replace(/[\u4e00-\u9fa5\d]/g,'');" value="" />

  

min、max 和 step 属性用于包含数字、日期的 input 类型约束。
min 属性规定输入域所允许的最小值。
max 属性规定输入域所允许的最大值。
step 属性为输入域规定合法的数字间隔

猜你喜欢

转载自www.cnblogs.com/sy11112027/p/11027706.html
今日推荐