本文摘自PHP中文网,作者angryTom,侵删。

简介:公司网站做试用用户申请窗口,为防止用户错误输入,给予input适当控制,能够防止用户输入错误,同时也能减少公司垃圾数据,当然,如果更大程度避免垃圾数据,最好还是后端正则验证,下面是我记录的input常用正则表达式,希望能给大家带来方便。
( 推荐学习:html教程 )
下面是input经常用到正则表达式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <!doctype html>
< html >
< meta charset = "utf-8" />
< body >只允许输入正整数:
< input type = 'text' onkeyup = "this.value=this.value.replace(/^(0+)|[^\d]+/g,'')" >
< br />
< br />只允许输入英文:
< input type = "text" onkeyup = "this.value=this.value.replace(/[^a-zA-Z]/g,'')" >
< br />
< br />只允许允许输入数字和字母:
< input onKeyUp = "value=value.replace(/[\W]/g,'')" >
< br />
< br />允许输入大小写字母、数字、下划线:
< input type = "text" onkeyup = "this.value=this.value.replace(/[^\w_]/g,'');" >
< br />
< br />允许输入小写字母、数字、下划线:
< input type = "text" onkeyup = "this.value=this.value.replace(/[^a-z0-9_]/g,'');" >
< br />
< br />允许输入数字和小数点:
< input type = "text" onkeyup = "this.value=this.value.replace(/[^\d.]/g,'')" >
< br />
< br />允许输入中文、数字、英文:
< input onkeyup = "value=value.replace(/[^\w\u4E00-\u9FA5]/g, '')" >
< br />
< br />
</ body >
</ html >
|
以上就是input输入框只能输入数字、字母相关组合(正则表达式)的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
html如何空格
html 空链接 href="#"与href="javascript:void(0)"的区别
html网页的主体标签是什么?
怎么在html增加css
如何使用css去掉a标签的下划线?(代码详解)
html的语法详解
html的有序列表、无序列表与定义列表应该如何使用
xml与html的区别
css+html实现模拟百度首页(附代码)
如何使用html实现流星雨的效果(代码)
更多相关阅读请进入《input》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » input输入框只能输入数字、字母相关组合(正则表达式)