欢迎光临
我们一直在努力

互联网页面浏览限制实现总结 (1)-ASP教程,ASP应用

建站超值云服务器,限时71元/月

1.文本框输入限制 实现限制输入大、小写英文,数字,浮点小数,日期,中文,部分英文,部分中文等众多功能。直接加入到html代码中即可使用。

<script>

function reginput(obj, reg, inputstr)

{

var docsel = document.selection.createrange()

if (docsel.parentelement().tagname != "input") return false

osel = docsel.duplicate()

osel.text = ""

var srcrange = obj.createtextrange()

osel.setendpoint("starttostart", srcrange)

var str = osel.text + inputstr + srcrange.text.substr(osel.text.length)

return reg.test(str)

}

</script>
小写英文:<xmp style= "display:inline"> </xmp>

<input onkeypress = "return reginput(this, /^[a-z]*$/, string.fromcharcode(event.keycode))"

onpaste = "return reginput(this, /^[a-z]*$/, window.clipboarddata.getdata(text))"

ondrop = "return reginput(this, /^[a-z]*$/, event.datatransfer.getdata(text))"

style="ime-mode:disabled"

><br>
大写英文:<xmp style= "display:inline"> </xmp>

<input onkeypress = "return reginput(this, /^[a-z]*$/, string.fromcharcode(event.keycode))"

onpaste = "return reginput(this, /^[a-z]*$/, window.clipboarddata.getdata(text))"

ondrop = "return reginput(this, /^[a-z]*$/, event.datatransfer.getdata(text))"

style="ime-mode:disabled">

<br>
任意数字:<xmp style="display:inline"> </xmp>

<input onkeypress = "return reginput(this, /^[0-9]*$/, string.fromcharcode(event.keycode))"

onpaste = "return reginput(this, /^[0-9]*$/, window.clipboarddata.getdata(text))"

ondrop = "return reginput(this, /^[0-9]*$/, event.datatransfer.getdata(text))"

style="ime-mode:disabled"

><br>
限2位小数:<xmp style="display:inline"> </xmp>

<input onkeypress = "return reginput(this, /^\d*\.?\d{0,2}$/, 
string.fromcharcode(event.keycode))"

onpaste = "return reginput(this, /^\d*\.?\d{0,2}$/, 
window.clipboarddata.getdata(text))"

ondrop = "return reginput(this, /^\d*\.?\d{0,2}$/, 
event.datatransfer.getdata(text))"

style="ime-mode:disabled"

> 如: 123.12<br>


日  期:<xmp style="display:inline"> </xmp>

<input onkeypress = "return reginput(this, /^\d{1,4}
([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/, 
string.fromcharcode(event.keycode))"

onpaste = "return reginput(this, /^\d{1,4}([-\/](\d{1,2}
([-\/](\d{1,2})?)?)?)?$/, 
window.clipboarddata.getdata(text))"

ondrop = "return reginput(this, /^\d{1,4}([-\/](\d{1,2}
([-\/](\d{1,2})?)?)?)?$/, 
event.datatransfer.getdata(text))"

style="ime-mode:disabled"

> 如: 2002-9-29<br>
任意中文:<xmp style="display:inline"> </xmp>

<input onkeypress = "return reginput(this, /^$/, 
string.fromcharcode(event.keycode))"

onpaste = "return reginput(this, /^[\u4e00-\u9fa5]*$/, 
window.clipboarddata.getdata(text))"

ondrop = "return reginput(this, /^[\u4e00-\u9fa5]*$/, 
event.datatransfer.getdata(text))"

><br>
部分英文:<xmp style="display:inline"> </xmp>

<input onkeypress = "return reginput(this, /^[a-e]*$/, 
string.fromcharcode(event.keycode))"

onpaste = "return reginput(this, /^[a-e]*$/, 
window.clipboarddata.getdata(text))"

ondrop = "return reginput(this, /^[a-e]*$/, 
event.datatransfer.getdata(text))"

style="ime-mode:disabled"

> 范围: a,b,c,d,e<br>
部分中文:<xmp style="display:inline"> </xmp>
<script language=javascript>

function checkchinese(oldlength, obj)

{

var otr = window.document.selection.createrange()

var reg = /[^一二三四五六七八九十]/g

otr.movestart("character", -1*(obj.value.length-oldlength))

otr.text = otr.text.replace(reg, "")

}

</script>

<input onkeypress="return false" onkeydown=
"settimeout(checkchinese(+this.value.length+,+this.uniqueid+), 
1)"

onpaste = "return reginput(this, /^[一二三四五六七八九十]*$/, 
window.clipboarddata.getdata(text))"

ondrop = "return reginput(this, /^[一二三四五六七八九十]*$/,
 event.datatransfer.getdata(text))"

> 范围: 一二三四五六七八九十<br>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 互联网页面浏览限制实现总结 (1)-ASP教程,ASP应用
分享到: 更多 (0)