JS can only be a number and a decimal point
0. Cannot enter Chinese
1) <input onpaste= "return false;" type= "text" name= "TextField" style= "width:400px"; Ime-mode:disabled "Value=" ">
2) <script>
function Chkit (frm) {
if (Frm.n1.value.length>0&&frm.n1.value.match (/[\x01-\xff]*/) ==false) {
Alert (' N1 cannot enter Chinese! ')
Frm.n1.focus ();
return false;
}
}
</script>
<body>
<form onsubmit= "return Chkit" >
<input name= "n1″>
<input name= "n2″>
<input name= "SMT" type= "submit" value= "submitted" >
</form>
</body>
1. Text box can only enter a numeric code (decimal point can not enter)
<input onkeyup= "This.value=this.value.replace (/\d/g,") "Onafterpaste=" This.value=this.value.replace (/\D/g, ")" >
2. Only numbers can be entered and the decimal point may 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 only number '); this.value=";} " >
3. Number and decimal method two
<input type=text t_value= "" o_value= "" onkeypress= "if!this.value.match (/^[\+\-]?\d*?\.? \d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match/^ (?: [\+\-]?\d+ (?: \. \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+ (?: \. \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 characters 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. Can only enter English letters and numbers, can not enter Chinese
<input onkeyup= "Value=value.replace (/[^\w\.\/]/ig,") ">
6. Only digital 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 (number, Chinese can be entered), can not enter letters and operational symbols:
<input onkeypress= "If" (event.keycode<48 | | event.keycode>57) && event.keycode!=46 | |/\.\d\d$/.test ( Value)) Event.returnvalue=false ">
8. After the decimal point can only have up to two digits (numbers, letters, Chinese can be entered), you can enter operational symbols:
<input onkeyup= "This.value=this.value.replace (/^ (\-) * (\d+) \. ( \d\d). *$/, ' $1$2.$3′ ' >
prohibit special characters:
Onkeypress= "if (Event.keycode < | | | Event.keycode >) event.returnvalue = false;"
Only Chinese characters can be entered:
<input onkeyup= "Value=value.replace (/[^/u4e00-/u9fa5]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/u4e00-/u9fa5]/g, ")" >
style= "ime-mode:disabled" forbidden Chinese Character input method
Only numbers can be entered:
<input onkeyup= "Value=value.replace (/[^/d]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ")" >
Only English and numerals can be entered:
<input onkeyup= "Value=value.replace (/[/w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/d]/g, ")" >
The control input box can only enter text or numbers, or it may not allow special characters to be entered
It is not allowed to enter the following characters: (like ^&*, etc.) <br>
<textarea rows=2 cols=20 name=comments onkeypress= "if (Event.keycode > && event.keycode < 48) | | (Event.keycode > && event.keycode < 65) | | (Event.keycode > && event.keycode < 97)) Event.returnvalue = false; " >
No space input only
Onkeyup= "Value=value.replace (//s/g,") "
Onkeydown= "if (event.keycode==32) return false"
Only Chinese and English can be entered:
Onkeyup= "Value=value.replace (/[^/a-za-z/u4e00-/u9fa5]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^/a-za-z/u4e00-/u9fa5]/g, ")"
Do not allow special characters and spaces to be entered:
<input id= "code" onkeypress= "Return Validatespecialcharacter ()," onblur= "Validate (This)"/>
————————————————————————————————————————
Cannot be empty
<input onblur= "If" (This.value.replace (/^ +| +$/g, ") = =") alert (' cannot be empty! ') " >
Judging characters consist of letters and numbers, underscores, and dots. And the beginning can only be underlined and letters.
/^ ([A-za-z_]{1}) ([\w]*) $/g.test (str)
Only numbers can be entered
<input name= "text" type= "text" id= "NewPage" onkeyup= "Value=value.replace (/\d/g,") "Onafterpaste=" value= Value.replace (/\d/g, ")" >
can only enter Chinese
<input type= "text" onkeyup= "Value=value.replace (/[^\u4e00-\u9fa5]/g,") ">
can only enter English
<input type= "text" onkeyup= "Value=value.replace (/[^\a-\z\a-\z]/g,") ">
<input type= "text" onkeyup= "Value=value.replace (/[^a-za-z]/g,") ">
——————————————————————————————————————–
1. Text box can only enter a numeric code (decimal point can not enter)
<input onkeyup= "This.value=this.value.replace (//d/g,") "Onafterpaste=" This.value=this.value.replace (//D/g, ")" >
2. Only numbers can be entered and the decimal point may 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 only number '); this.value=";} " >
3. Number and decimal method two
<input type=text t_value= "" o_value= "" onkeypress= "if!this.value.match (/^[/+/-]?/d*?/.? /d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match/^ (?: [/+/-]?/d+ (?:/. /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+ (?:/. /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 characters 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. Can only enter English letters and numbers, can not enter Chinese
<input onkeyup= "Value=value.replace (/[^/w/.//]/ig,") ">
6. Only digital 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 (number, Chinese can be entered), can not enter letters and operational symbols:
<input onkeypress= "If" (event.keycode<48 | | event.keycode>57) && event.keycode!=46 | |//./d/d$/.test ( Value)) Event.returnvalue=false ">
8. After the decimal point can only have up to two digits (numbers, letters, Chinese can be entered), you can enter operational symbols:
<input onkeyup= "This.value=this.value.replace (/^ (/-) * (/d+)/. ( /D/D). *$/, ' $1$2.$3′ ' >
The
can only be entered in Chinese, English, numerals, @ symbols, and. Symbols
<input type= "Text onkeyup=" Value=value.replace (/[^\a-\z\a-\z0-9\u4e00-\u9fa5\@\.] /g, ")"
only allow input in English, and cannot paste or eject the Paste menu
<input type= "Text onkeyup=" Value=value.replace (/[^\a-\z\a-\z]/g, ")" onkeydown= "Fnckeystop (event)" onpaste= "return false" OnContextMenu = ' return false '/>
only numbers and dots can be entered (note: in [^\d\.] D cannot be written in uppercase D, otherwise it becomes all characters except numbers
<input name= "Price" type= "text" size= "8″maxlength=" 8″onkeyup= "value=" Value.replace (/[^\d\.) /g, ")"
in summary: First in <input> input onkeyup= "Value=value.replace (/[^\x]/g,") "and then in (/[\x]/g,") to replace the X you want to enter the code you can
Chinese: u4e00-u9fa5
Number: D, 0-9
English: A-Z, a-Z
other symbols @, dots, or other symbols. Also can be multiple, with \ Separated on the line.
For example:
Chinese, English, and numbers with @ sign dot notation: \a-\z\a-\z0-9\u4e00-\u9fa5\@\.
If you want to be in the text box can not right-click pop-up menu and can not paste into the copy of the information in the <input> input onkeydown= "Fnckeystop (event)" onpaste= "return false" OnContextMenu = "return false;"
—————————————————————————————————————————————
First, you only allow numbers and decimal points to be entered.
<input onkeypress= "return (/[/d.] /.test (String.fromCharCode (Event.keycode)) "style=" ime-mode:disabled ">
Second, judge the more detailed, even 22. 2 It's not a number, it's a judgment.
<script>
function Check () {
if (isNaN (Tt.value))
{alert ("illegal character!) ”);
Tt.value= "";}
}
</script>
<input type= "text" Name= "tt" onkeyup= "check ();" >
Third, only integer input is allowed. In fact, can also be based on the third article to extrapolate to do some restrictions.
<script language=javascript>
function Onlynum ()
{
if (!) ( EVENT.KEYCODE==46) &&! (event.keycode==8) &&! (event.keycode==37) &&! (event.keycode==39))
if (!) ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105)))
Event.returnvalue=false;
}
</script><input onkeydown= "Onlynum ();" Style= "ime-mode:disabled>
conclusion, in fact
Style= "ime-mode:disabled
This sentence is more practical. Closes the input method. Saves some people to open the full angle input number, the result input does not go in to seek your kutianmalei, also blames you to design is not good.
Only allow numbers to be entered
<input name= "username" type= "text" onkeyup= "Value=this.value.replace (//d+/g,") ">
Only English letters, numbers, and underscores are allowed (in the following two ways)
<input name= "Userna one, allowing only numbers and decimal points to be entered.
<input onkeypress= "return (/[/d.] /.test (String.fromCharCode (Event.keycode)) "style=" ime-mode:disabled ">
Second, judge the more detailed, even 22. 2 It's not a number, it's a judgment.
<script>
function Check () {
if (isNaN (Tt.value))
{alert ("illegal character!) ”);
Tt.value= "";}
}
</script>
<input type= "text" Name= "tt" onkeyup= "check ();" >
Third, only integer input is allowed. In fact, can also be based on the third article to extrapolate to do some restrictions.
<script language=javascript>
function Onlynum ()
{
if (!) ( EVENT.KEYCODE==46) &&! (event.keycode==8) &&! (event.keycode==37) &&! (event.keycode==39))
if (!) ( (event.keycode>=48&&event.keycode<=57) | | (event.keycode>=96&&event.keycode<=105)))
Event.returnvalue=false;
}
</script><input onkeydown= "Onlynum ();" Style= "ime-mode:disabled>
conclusion, in fact
Style= "ime-mode:disabled
This sentence is more practical. Closes the input method. Saves some people to open the full angle input number, the result input does not go in to seek your kutianmalei, also blames you to design is not good.
Only allow numbers to be entered
<input name= "username" type= "text" onkeyup= "Value=this.value.replace (//d+/g,") ">
Only English letters, numbers, and underscores are allowed (in the following two ways)
<input name= "username" type= "text" style= "ime-mode:disabled" >
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/w/.//]/ig,") ">
Only English letters, numbers and &=@ are allowed
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/w=@&]|_/ig,") ">
Only allow Chinese characters to be entered
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/u4e00-/u9fa5]/g,") ">
Me "type=" text "style=" ime-mode:disabled ">
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/w/.//]/ig,") ">
Only English letters, numbers and &=@ are allowed
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/w=@&]|_/ig,") ">
Only allow Chinese characters to be entered
<input name= "username" type= "text" onkeyup= "Value=value.replace (/[^/u4e00-/u9fa5]/g,") ">