来源:www.cncfan.com | 2006-10-30 | (有2016人读过)
<P><script> function regInput(reg) { var srcElem = event.srcElement var oSel = document.selection.createRange() var srcRange = srcElem.createTextRange() oSel.setEndPoint("StartToStart", srcRange) var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length) event.returnValue = reg.test(num) } </script></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> <script language=javascript> function checkChinese(oldLength, obj) { var oTR = window.document.selection.createRange() oTR.moveStart("character", -1*(obj.value.length-oldLength)) oTR.text = oTR.text.replace(/[^一二三四五六七八九十]/g, "") } </script> <input onkeypress="return false" onkeydown="setTimeout('checkChinese('+this.value.length+','+this.uniqueID+')', 1)"> 范围: 一二三四五六七八九十 </P> <P> </P>
|