<strong>1.只能输入汉字的</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="16569" class="copybut" id="copybut16569" onclick="doCopy('code16569')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code16569"> <br><input onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))"> <br> </div> <br><strong>2.只能输入数字的</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="8283" class="copybut" id="copybut8283" onclick="doCopy('code8283')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code8283"> <br><input onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"> <br> </div> <br>简易禁止输入汉字 <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="86256" class="copybut" id="copybut86256" onclick="doCopy('code86256')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code86256"> <br><input type="text" style="ime-mode:disabled"> <br> </div> <br>输入数字和小数点: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="25777" class="copybut" id="copybut25777" onclick="doCopy('code25777')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code25777"> <br>onkeyup="value=value.replace(/[^d{1,}.d{1,}|d{1,}]/g,'')" <br> </div> <br>javascript 只能输入数字和":".2007-11-24 15:50<input type=text id="aa1" onkeyup="this.value=this.value.replace(/[^d&:]/g,'')" onblur="this.value=this.value.replace(/[^d&:]/g,'')" onafterpaste="this.value=this.value.replace(/[^d&:]/g,'')"/> <br>只能数字和":",例如在输入时间的时候可以用到。 <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="7215" class="copybut" id="copybut7215" onclick="doCopy('code7215')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code7215"> <br><input type=text id="aa" onkeyup="value=value.replace(/[^w&=]|_/ig,'')" onblur="value=value.replace(/[^w&=]|_/ig,'')" /> <br> </div> <br>只能输入字母和等号,不能输入汉字。 <br><br><strong>其它的东西</strong>: <br>只能输入数字的脚本javascript- - <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="89461" class="copybut" id="copybut89461" onclick="doCopy('code89461')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code89461"> <br><input onkeyup="this.value=this.value.replace(/D/g,'')" onafterpaste="this.value=this.value.replace(/D/g,'')"> <br> </div> <br>上半句意思是键盘键入只能是数字,下半句是粘贴也只能是数字 <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="16164" class="copybut" id="copybut16164" onclick="doCopy('code16164')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code16164"> <br><input name=txt1 onchange="if(/D/.test(this.value)){alert('只能输入数字');this.value='';}"> <br><input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"> <br> </div> <br><strong>3.JavaScript限制只能输入数字和英文</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="36054" class="copybut" id="copybut36054" onclick="doCopy('code36054')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code36054"> <br>function isregname( checkobj) <br>{ <br>var checkOK = "0123456789-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; <br>var checkStr = checkobj; <br>var allValid = true; <br>var decPoints = 0; <br>for (i = 0; i < checkStr.length; i ) <BR>{ <BR>ch = checkStr.charAt(i); <BR>for (j = 0; j < checkOK.length; j ) <BR>if (ch == checkOK.charAt(j)) <BR>break; <BR>if (j == checkOK.length) <BR>{ <BR>allValid = false; <BR>break; <BR>} <BR>} <BR>return (allValid) <BR>} <BR>---------------- <BR>if(!(isregname(obj.loginname.value))){ <BR>alert("[会员代号]不符合规范,会员代号只能是英文字母或数字"); <BR>obj.loginname.focus(); <BR>return(false); <BR>} <BR>if(!(isregname(obj.password.value))){ <BR>alert("[密码]不符合规范,密码只能是英文字母或数字"); <BR>obj.password.focus(); <BR>return(false); <BR>} <BR></div> <BR><STRONG>4.javascript只能输入英文和数字的输入框</STRONG> <BR><div class="codetitle"><span><a style="CURSOR: pointer" data="2942" class="copybut" id="copybut2942" onclick="doCopy('code2942')"><U>复制代码</U></a></span> 代码如下:</div><div class="codebody" id="code2942"> <BR><input onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"> <br> </div> <br><strong>5.可以用Javascript对文本框进行检查,过滤掉非0-9的字符</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="2278" class="copybut" id="copybut2278" onclick="doCopy('code2278')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code2278"> <br><script language="javascript" event="onkeydown" for="document"> <br> if(event.srcElement.name=='TextBox1') <br> { <br> if(!KeyIsNumber(event.keyCode)) <br> { <br> return false;//这句话最关键 <br> } <br> } <br> </script> <br> <script language="javascript"> <br> function KeyIsNumber(KeyCode) <br> { <br> //如果输入的字符是在0-9之间,或者是backspace、DEL键 <br> if(((KeyCode>47)&&(KeyCode<58))||(KeyCode==8)||(KeyCode==46)) <br> { <br> return true; <br> } <br> else <br> { <br> return false; <br> } <br> } <br> </script>[url=http://blog.csdn.net/xujh/admin/EditPosts.aspx][/url] <br> </div> <br><strong>6.限制在文本框里面只能输入IP地址格式</strong> <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="77711" class="copybut" id="copybut77711" onclick="doCopy('code77711')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code77711"> <br><HTML> <br><head> <br><meta http-equiv="Content-Type" content="text/HTML; charset=gb2312"> <br><meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <br><meta name="ProgId" content="FrontPage.Editor.Document"> <br><style> <br>.a3{width:30;border:0;text-align:center} <br></style> <br><script> <br>function mask(obj){ <br>obj.value=obj.value.replace(/[^d]/g,'') <br>key1=event.keyCode <br>if (key1==37 || key1==39) <br>{ obj.blur(); <br>nextip=parseInt(obj.name.substr(2,1)) <br>nextip=key1==37?nextip-1:nextip 1; <br>nextip=nextip>=5?1:nextip <br>nextip=nextip<=0?4:nextip <BR>eval("ip" nextip ".focus()") <BR>} <BR>if(obj.value.length>=3) <br>if(parseInt(obj.value)>=256 || parseInt(obj.value)<=0) <BR>{ <BR>alert(parseInt(obj.value) "IP地址错误!") <BR>obj.value="" <BR>obj.focus() <BR>return false; <BR>} <BR>else <BR>{ obj.blur(); <BR>nextip=parseInt(obj.name.substr(2,1)) 1 <BR>nextip=nextip>=5?1:nextip <br>nextip=nextip<=0?4:nextip <br>eval("ip" nextip ".focus()") <br>} <br>} <br>function mask_c(obj) <br>{ <br>clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,'')) <br>} <br></script> <br><title>IP地址输入</title> <br></head> <br><body>IP地址输入 <br><div style="border-width:1;border-color:balck;border-style:solid;width:165;font-size:9pt"> <br><input type=text name=ip1 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>. <br><input type=text name=ip2 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>. <br><input type=text name=ip3 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()>. <br><input type=text name=ip4 maxlength=3 class=a3 onkeyup="mask(this)" onbeforepaste=mask_c()> <br></div> <br></body> <br></HTML> <br> </div>