简介:公司网站做试用用户申请窗口,为防止用户错误输入,给予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输入框只能输入数字、字母相关组合(正则表达式)的详细内容