禁止复制:
oncopy="return false"
禁止粘贴:
onpaste="return false"
禁止剪切:
oncut="return false"
关闭自动完成功能(缓存):
autocomplete="off"
自动获得焦点:
autofocus="autofocus"
禁用自动更正:
autocorrect="off"
来关闭键盘默认首字母大写(移动端):
autocapitalize="off"
不对元素的文本进行拼写检查:
spellcheck="false"
禁止右键弹出:
oncontextmenu="return false"
只输入大小写字母、数字、下划线:
<input type = "text" onkeyup="this.value=this.value.replace(/[^\w_]/g,'');"> 
输入数字和点
<input type="text" onkeyup="value=value.replace(/[^\d.]/g,'')">
输入小写字母、数字、下划线:
<input type = "text" onkeyup="this.value=this.value.replace(/[^a-z0-9_]/g,'');"> 
输入中文: 
<input type = "text" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')"> 
输入数字: 
<input type = "text" onkeyup="this.value=this.value.replace(/\D/g,'')"> 
输入英文: 
<input type = "text" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')"> 
输入中文、数字、英文: 
<input onkeyup = "value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')" >
输入数字和字母:
<input onKeyUp = "value=value.replace(/[\W]/g,'')" >
除了英文的标点符号以外,其他的都可以中文,英文字母,数字,中文标点
<input type="text" onkeyup="this.value=this.value.replace(/^[^!@#$%^&*()-=+]/g,'')">
只能输入数字代码(小数点也不能输入)
<input onkeyup = "this.value=this.value.replace(/\D/g,'')">
只能输入数字,能输小数点:
<input onkeyup = "if(isNaN(value))execCommand('undo')">
<input name = txt1 onchange="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}">
只能输入英文字母和数字, 不能输入中文
<input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
只能输入数字和英文
<input onKeyUp = "value=value.replace(/[^\d|chun]/g,'')" >
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐