1. Can only enter the Chinese characters
Copy Code code as follows:
<input onkeyup= "Value=value.replace (/[^\u4e00-\u9fa5]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\u4e00-\u9fa5]/g, ') ">
2. Can only enter the number of
Copy Code code as follows:
<input onkeyup= "Value=value.replace (/[^\d]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ') ">
Simple prohibition of entering Chinese characters
Copy Code code as follows:
<input type= "text" style= "ime-mode:disabled" >
Enter numbers and decimal points:
Copy Code code as follows:
Onkeyup= "Value=value.replace (/[^\d{1,}\.\d{1,}|\d{1,}]/g,") "
JavaScript can only enter numbers and ":". 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, ') "/>
Only digits and ":", for example, can be used when entering the time.
Copy Code code as follows:
<input type=text id= "AA" onkeyup= "Value=value.replace (/[^\w&=]|_/ig, '") "onblur=" Value=value.replace (/[^\w &=]|_/ig, ")"/>
You can only enter letters and equal signs, and you cannot enter Chinese characters.
something else.:
Scripts that can only enter numbers javascript--
Copy Code code as follows:
<input onkeyup= "This.value=this.value.replace (/\d/g,") "Onafterpaste=" This.value=this.value.replace (/\D/g, " ) ">
The upper half means that the keyboard can only be typed as a number, and the second sentence is a paste and only a number.
Copy Code code as follows:
<input name=txt1 onchange= "if (/\d/.test (this.value)) {alert (' can only enter numbers '); this.value= ';} ' >
<input onkeyup= "if (isNaN (value)) ExecCommand (' Undo ') ' onafterpaste= ' if (isNaN (value)) ExecCommand (' Undo ') >
3.JavaScript Limit can only enter numbers and English
Copy Code code as follows:
function Isregname (checkobj)
{
var Checkok = "0123456789-_abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
var checkstr = checkobj;
var allvalid = true;
var decpoints = 0;
for (i = 0; i < checkstr.length; i++)
{
ch = checkstr.charat (i);
for (j = 0; J < Checkok.length; J + +)
if (ch = = Checkok.charat (j))
Break
if (j = = Checkok.length)
{
Allvalid = false;
Break
}
}
Return (Allvalid)
}
----------------
if (!) ( Isregname (Obj.loginname.value))) {
Alert ("[member code] does not conform to the specification, the member code can only be English letters or numbers");
Obj.loginname.focus ();
return (false);
}
if (!) ( Isregname (Obj.password.value))) {
Alert ("[Password] is not in accordance with the specification, the password can only be English letters or numbers");
Obj.password.focus ();
return (false);
}
4.javascript input Box can only be entered in English and digital
Copy Code code as follows:
<input onkeyup= "Value=value.replace (/[\w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ') ">
5. You can use JavaScript to check the text box to filter out non-0-9 characters
Copy Code code as follows:
<script language= "javascript" event= "onkeydown" for= "Document" >
if (event.srcelement.name== ' TextBox1 ')
{
if (! Keyisnumber (Event.keycode))
{
Return false;//This sentence is the most critical
}
}
</script>
<script language= "JavaScript" >
function Keyisnumber (keycode)
{
If the character entered is between 0-9, or the backspace, Del key
if ((keycode>47) && (keycode<58) | | (keycode==8) | | (keycode==46))
{
return true;
}
Else
{
return false;
}
}
</script>[url=http://blog.csdn.net/xujh/admin/editposts.aspx][/url]
6. Restrict to text box only enter IP address format
Copy Code code as follows:
<HTML>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<meta name= "generator" content= "Microsoft FrontPage 4.0" >
<meta name= "ProgId" content= "FrontPage.Editor.Document" >
<style>
. A3{width:30;border:0;text-align:center}
</style>
<script>
function Mask (obj) {
Obj.value=obj.value.replace (/[^\d]/g, "")
Key1=event.keycode
if (key1==37 | | key1==39)
{Obj.blur ();
Nextip=parseint (Obj.name.substr (2,1))
nextip=key1==37?nextip-1:nextip+1;
Nextip=nextip>=5?1:nextip
Nextip=nextip<=0?4:nextip
eval ("IP" +nextip+ ". Focus ())"
}
if (obj.value.length>=3)
if (parseint (obj.value) >=256 | | parseint (obj.value) <=0)
{
Alert (parseint (obj.value) + "IP address error! ")
Obj.value= ""
Obj.focus ()
return false;
}
Else
{Obj.blur ();
Nextip=parseint (Obj.name.substr (2,1)) +1
Nextip=nextip>=5?1:nextip
Nextip=nextip<=0?4:nextip
eval ("IP" +nextip+ ". Focus ())"
}
}
function Mask_c (obj)
{
Clipboarddata.setdata (' Text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ')
}
</script>
<TITLE>IP Address Input </title>
<BODY>IP Address input
<div style= "Border-width:1;border-color:balck;border-style:solid;width:165;font-size:9pt" >
<input type=text name=ip1 maxlength=3 class=a3 onkeyup= "Mask (This)" Onbeforepaste=mask_c ().
<input type=text name=ip2 maxlength=3 class=a3 onkeyup= "Mask (This)" Onbeforepaste=mask_c ().
<input type=text name=ip3 maxlength=3 class=a3 onkeyup= "Mask (This)" Onbeforepaste=mask_c ().
<input type=text name=ip4 maxlength=3 class=a3 onkeyup= "Mask (This)" Onbeforepaste=mask_c () >
</div>
</body>
</HTML>