【正则表达式】input 只能输入汉字、数字、字母等
只能输入汉字(有闪动):
<input type="text" id="searchStr" name="searchStr" value="请输入姓名" onkeyup="this.value=this.value.replace(/[^u4E00-u9FA5]/g,"")" />
只能输入数字(有闪动):
<input type="text" id="searchStr" name="searchStr" value="请输入身份证号码" onkeyup="this.value=this.value.replace(/[^d]/g,"")" />
只能输入汉字、字母和数字(无闪动):
<input type="text" id="searchStr" name="searchStr" value="请输入姓名或身份证号" onkeypress="return /[wu4e00-u9fa5]/.test(String.fromCharCode(window.event.keyCode))" onpaste="return !/[^wu4e00-u9fa5]/g.test(window.clipboardData.getData("Text"))" ondragenter="return false"/>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: c# 定义动态数组方法
- 下一篇: javascript/JS限制用户名只能输入 汉字字母和数字下划线