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]*$/,
评论0