<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>
|