1. Only Chinese characters can be entered
Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ u4E00-\ u9FA5]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ u4E00-\ u9FA5]/g, '')">
2. Only numbers can be entered
Copy codeThe Code is as follows:
<Input onkeyup = "value = value. replace (/[^ \ d]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')">
Chinese characters cannot be entered.
Copy codeThe Code is as follows:
<Input type = "text" style = "ime-mode: disabled">
Enter a number and a decimal point:
Copy codeThe Code is as follows:
Onkeyup = "value = value. replace (/[^ \ d {1 ,}\. \ d {1 ,}| \ d {1,}]/g ,'')"
Javascript can only enter numbers and ":". <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 numbers and ":" are allowed. For example, they can be used when you enter the time.
Copy codeThe Code is as follows:
<Input type = text id = "aa" onkeyup = "value = value. replace (/[^ \ w & =] | _/ig, '')" onblur = "value = value. replace (/[^ \ w & =] | _/ig, '')"/>
Only letters and equal signs are allowed, and Chinese characters are not allowed.
Other things:
Only scripts with numbers can be entered --
Copy codeThe Code is as follows:
<Input onkeyup = "this. value = this. value. replace (/\ D/g, '')" onafterpaste = "this. value = this. value. replace (/\ D/g, '')">
The upper half means that only numbers can be typed on the keyboard, and only numbers can be pasted in the lower half.
Copy codeThe Code is as follows:
<Input name = txt1 onchange = "if (/\ D /. test (this. value) {alert ('only numbers allowed '); this. value = '';}">
<Input onkeyup = "if (isNaN (value) execCommand ('undo ')" onafterpaste = "if (isNaN (value) execCommand ('undo')">
3. JavaScript restrictions: only numbers and English letters can be entered
Copy codeThe Code is 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 comply with the specifications. The Member Code can only be English letters or numbers ");
Obj. loginname. focus ();
Return (false );
}
If (! (Isregname (obj. password. value ))){
Alert ("[Password] does not comply with the specifications. The password can only be English letters or numbers ");
Obj. password. focus ();
Return (false );
}
4. javascript can only enter input boxes of English letters and numbers
Copy codeThe Code is 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 and filter out non-0-9 characters.
Copy codeThe Code is as follows:
<Script language = "javascript" event = "onkeydown" for = "document">
If (event. srcElement. name = 'textbox1 ')
{
If (! KeyIsNumber (event. keyCode ))
{
Return false; // The most important sentence
}
}
</Script>
<Script language = "javascript">
Function KeyIsNumber (KeyCode)
{
// If the entered character is between 0-9, or the backspace or 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. Only the IP address format can be entered in the text box.
Copy codeThe Code is as follows:
<HTML>
<Head>
<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>
</Head>
<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>