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,'')">  
//只能输入字母和中文
<input onkeyup="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,'')">  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。