1. Only import and paste Chinese characters
<input onkeyup= "Value=value.replace (/[^u4e00-u9fa5]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^u4e00-u9fa5]/g, ')) "><br/>
3. Only enter and paste numbers
<input onkeyup= "This.value=this.value.replace (/d/g, ')" onafterpaste= "This.value=this.value.replace (/D/g, ')" /><br/>
5. Digital scripting
<input onkeyup= "if (/d/.test (this.value)) {alert (' Input number only '); this.value= ';}" ><br/>
6. Only enter numbers and English
<input onkeyup= "Value=value.replace (/[w]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^d]/g, ')) "><br/>
8. Simple forbidden to enter Chinese characters
<input style= "ime-mode:disabled" > IME does not convert, but can be pasted on <br/>
9. Enter numbers and decimal points
<input onkeyup= "Value=value.replace (/[^d{1,}.d{1,}|d{1,}]/g, ')"/><br/>
10. Only numbers and "-", for example, can be used when entering a time
<input onkeyup= "Value=value.replace (/[^w&=]|_/ig, ')" onblur= "Value=value.replace (/[^w&-]|_/ig, ')"/ >
JS control input character limit
Enter key to move the cursor to the next input box
The code is as follows:
<input onkeydown= "if (event.keycode==13) event.keycode=9" > can only be Chinese
<input onkeyup= "Value=value.replace (/[-~]/g, ')" onkeydown= "if (event.keycode==13) event.keycode=9" > Shielded Input Method <input style= "ime-mode:disabled" onkeydown= "if (event.keycode==13) event.keycode=9" > can only input English and digital
<input onkeyup= "Value=value.replace (/[/w]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ') "onkeydown=" if (event.keycode==13) event.keycode=9 "> can only be digital
<input onkeyup= "Value=value.replace (/[^/d]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ')) ">
Can only be displayed, cannot be modified
The code is as follows:
<input readonly value= "can only display, can not be modified" > can only lose numbers, determine the value of the key
<script language=javascript>
function Onlynum ()
{
if (! ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105) | | (event.keycode==8)))
Event.returnvalue=false;
}
</script>
<input onkeydown= "Onlynum (); >
1. Text box can only enter a numeric code (the decimal point can not be entered)
<input onkeyup= "This.value=this.value.replace (//d/g, ')" onafterpaste= "This.value=this.value.replace (//D/g, ' ) ">
2. Only the number can be entered and the decimal point will be lost.
<input onkeyup= "if (IsNaN (value)) ExecCommand (' Undo ')" Onafterpaste= "if (IsNaN (value)) ExecCommand (' Undo ')" >
<input name=txt1 onchange= "if (//d/.test (this.value)) {alert (' Input number only '); this.value= ';}" >
3. Number and decimal method two
The code is as follows:
<input type=text t_value= "" o_value= "" onkeypress= "if (!this.value.match.? /d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match (?: [/^ (?:/. /d+)?)? $/)) This.o_value=this.value "onkeyup=" if (!this.value.match (/^[/+/-]?/d*?/.? /d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match (?: [/^ (?:/. /d+)?)? $/)) This.o_value=this.value "onblur=" if (!this.value.match (?: [/^ (?:/. /d+)? | /./d*?)? $/) this.value=this.o_value;else{if (This.value.match (/^/./d+$/)) this.value=0+this.value;if (This.value.match (/^ /.$/)) This.value=0;this.o_value=this.value} ">
4. Only letters and kanji can be entered
<input onkeyup= "Value=value.replace (/[/d]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[/d]/g, ') "maxlength=10 name=" Numbers ">
5. Only English letters and numbers can be entered, not Chinese
<input onkeyup= "Value=value.replace (/[^/w/.//]/ig, ')" >
6. Only enter numbers and English
<font color= "Red" >chun</font>
<input onkeyup= "Value=value.replace (/[^/d|chun]/g, ')" >
7. Only a maximum of two digits after the decimal point (numeric, Chinese can be entered), can not enter letters and operation symbols: <input onkeypress= "if ((event.keycode<48 | | event.keycode>57) & & Event.keycode!=46 | | ./d/d$/.test (value) event.returnvalue=false ">8. Only up to two digits after the decimal point (numbers, letters, Chinese can be entered), you can enter the operation symbol:
<input onkeyup= "This.value=this.value.replace (/^ (/-) * (/d+)/. ( /D/D). *$/, ' $1$2.$3 ') ">
can only be numbers and decimal points and plus minus multiply
9. Only numbers, decimal points, negative numbers can be entered
The code is as follows:
<input name= "Input" type= "text" onkeyup= "Jhshnumbertext (This)" id= "title" >
<script language= "javascript" type= "Text/javascript" >function Jhshnumbertext (a)
{
var fa= "";
if (a.value.substring (0,1) = = "-")
Fa= "-";
var str= (A.value.replace (/[^0-9.) /g, "). Replace (/[.) [0-9]*[.] /, ‘.‘);
if (str.substring (0,1) = = ".")
Str= "0" +STR;
A.VALUE=FA+STR;
}
</script>
1. Cancel the dashed box when the button is pressed, add the attribute value in input hidefocus or hidefocus=true
<input type= "Submit" value= "Commit" hidefocus= "true"/>
2. Read-only text box contents, add attribute value in input readonly
<input type= "text" readonly/>
3. Prevent the text document from being emptied (you can use the style content as a class reference)
<input type= "text" style= "Behavior:url (#default #savehistory);"/>
4.ENTER key to move the cursor to the next input box
<input type= "text" onkeydown= "if (event.keycode==13) event.keycode=9"/>
5. Only Chinese (with flashing)
<input type= "text" onkeyup= "Value=value.replace (/[-~]/g, ')" onkeydown= "if (event.keycode==13) event.keyCode=9"/ >
6. Only digital (with flashing)
<input type= "text" onkeyup= "Value=value.replace (/[^/d]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ') "/>
7. Only digital (no flashing)
<input type= "text" style= "ime-mode:disabled" onkeydown= "if (event.keycode==13) event.keycode=9" onkeypress= "if (( event.keycode<48 | | event.keycode>57)) Event.returnvalue=false "/>
8. Only input English and numerals (with flashing)
<input type= "text" onkeyup= "Value=value.replace (/[/w]/g, ')" onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ') "/>
9. Shielding Input Method
<input type= "text" name= "url" style= "ime-mode:disabled" onkeydown= "if (event.keycode==13) event.keycode=9"/>
10. Enter only digits, decimal point, minus (-) character (no flashing)
<input onkeypress= "if (event.keycode!=46 && event.keycode!=45 && (event.keycode<48 | | event.keycode>57)) Event.returnvalue=false "/>
11. Only two decimal places can be entered, three decimal places (with flashing)
<input type= "Text" maxlength= "9" onkeyup= "if (Value.match (/^/d{3}$/)) Value=value.replace (Value,parseint (value/ Value=value.replace (//./d*/./g, '. ') "onkeypress=" if ((event.keycode<48 | | event.keycode>57) && event.keycode!=46 && event.keycode!=45 | | Value.match (/^/d{3}$/) | | ./d{3}$/.test (value)) {Event.returnvalue=false} "/>
Regular and JS restricted input type