资料
表格
制度
合同
管理
职场
经营
创业
范文
总结
计划
作文
文章
美文
词句
教程
模板
图片
字体
图标
办公
人事
财务
生产
管理资源吧首页
>>>
教程
>>>
编程
>>>
正则表达式教程
>>>
正则限制文本输入
<P><img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%3E%0D%0A%20function%20regInput(reg)%0D%0A%20%7B%0D%0A%20%20var%20srcElem%20%3D%20event.srcElement%0D%0A%20%20var%20oSel%20%3D%20document.selection.createRange()%0D%0A%20%20var%20srcRange%20%3D%20srcElem.createTextRange()%0D%0A%20%20oSel.setEndPoint(%22StartToStart%22%2C%20srcRange)%0D%0A%20%20var%20num%20%3D%20oSel.text%20%2B%20String.fromCharCode(event.keyCode)%20%2B%20srcRange.text.substr(oSel.text.length)%0D%0A%20%20event.returnValue%20%3D%20reg.test(num)%0D%0A%20%7D%0D%0A%3C%2Fscript%3E"></P> <P>小写英文:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[a-z]*$/)" style="ime-mode:Disabled"> 大写英文:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[A-Z]*$/)" style="ime-mode:Disabled"> 任意数字:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^[0-9]*$/)" style="ime-mode:Disabled"> 限2位小数:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^\d*\.?\d{0,2}$/)" style="ime-mode:Disabled"> 如: 123.12 日 期:<xmp style="display:inline"> </xmp><input id=test onkeypress="regInput(/^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/)" style="ime-mode:Disabled"> 如: 2002-9-29 任意中文:<xmp style="display:inline"> </xmp><input onkeypress="regInput(/^$/)"> 部分英文:<xmp style="display:inline"> </xmp><input onkeypress="regInput(/^[a-e]*$/i)" style="ime-mode:Disabled"> 范围: a,b,c,d,e 部分中文:<xmp style="display:inline"> </xmp> <img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%20language%3Djavascript%3E%0D%0Afunction%20checkChinese(oldLength%2C%20obj)%0D%0A%7B%0D%0A%20var%20oTR%20%3D%20window.document.selection.createRange()%0D%0A%20oTR.moveStart(%22character%22%2C%20-1*(obj.value.length-oldLength))%0D%0A%20oTR.text%20%3D%20oTR.text.replace(%2F%5B%5E%E4%B8%80%E4%BA%8C%E4%B8%89%E5%9B%9B%E4%BA%94%E5%85%AD%E4%B8%83%E5%85%AB%E4%B9%9D%E5%8D%81%5D%2Fg%2C%20%22%22)%0D%0A%7D%0D%0A%3C%2Fscript%3E"> <input onkeypress="return false" onkeydown="setTimeout('checkChinese('+this.value.length+','+this.uniqueID+')', 1)"> 范围: 一二三四五六七八九十 </P> <P> </P>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行
]
教程首页
更多教程