<Input type = "text" name = "textfield" onKeyPress = "javascript: alert (event. keyCode); return flase">
1. Only numeric code can be entered in the text box (decimal point cannot be entered)
<Input onkeyup = "this. value = this. value. replace (/\ D/g, '')" onafterpaste = "this. value = this. value. replace (/\ D/g, '')">
2. Only numbers can be entered, and decimal points can be entered.
<Input onkeyup = "if (isNaN (value) execCommand ('undo ')" onafterpaste = "if (isNaN (value) execCommand ('undo')">
<Input name = txt1 onchange = "if (/\ D /. test (this. value) {alert ('only numbers allowed '); this. value = '';}">
3. Number and decimal point method 2
<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 + )? | \. \ 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 Chinese 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. Only English letters and numbers are allowed. Chinese characters are not allowed.
<Input onkeyup = "value = value. replace (/[^ \ w \. \/]/ig,'') ">
6. Only numbers and English letters can be entered. <font color = "Red"> chun </font>
<Input onKeyUp = "value = value. replace (/[^ \ d | chun]/g,'') ">
7. After the decimal point, you can enter a maximum of two digits (numbers and Chinese characters). You cannot enter letters or operator numbers:
<Input onKeyPress = "if (event. keyCode <48 | event. keyCode> 57) & event. keyCode! = 46 |/\. \ d $/. test (value) event. returnValue = false ">
8. A maximum of two digits (numbers, letters, and Chinese characters) can be entered after the decimal point. You can enter the operator number:
<Input onkeyup = "this. value = this. value. replace (/^ (\-) * (\ d + )\. (\ d ). * $/, '$1 $2. $ 3') ">
<Input onkeyup = "value = value. replace (/[^ \ d \.]/g,'') ">
<Input type = text onkeypress = "return event. keyCode> = 65" style = "ime-mode: disabled">
<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 + )? | \. \ 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} ">
<Input onkeyup = "this. value = this. value. replace (/\ D/g, '')" onafterpaste = "this. value = this. value. replace (/\ D/g, '')">
Or
<Input name = txt1 onchange = "if (/\ D /. test (this. value) {alert ('only numbers allowed '); this. value = '';}">
Or
<Input onkeyup = "if (isNaN (value) execCommand ('undo ')" onafterpaste = "if (isNaN (value) execCommand ('undo')">
Only numbers including decimal points can be entered in the restricted text box.
<Input onkeyup = "value = value. replace (/[^ \ d \.]/g,'') ">
Related Regular Expressions 1. only numbers and English letters can be entered: <input onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')" ID = "Text1" NAME = "Text1">
2. only numbers can be entered: <input onkeyup = "value = value. replace (/[^ \ d]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ d]/g, '')" ID = "Text2" NAME = "Text2">
3. only the full-width values can be entered: <input onkeyup = "value = value. replace (/[^ \ uFF00-\ uFFFF]/g, '')" onbeforepaste = "clipboardData. setData ('text', clipboardData. getData ('text '). replace (/[^ \ uFF00-\ uFFFF]/g, '')" ID = "Text3" NAME = "Text3">
4. 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, '')" ID = "Text4" NAME = "Text4">
When moved to the input box, it is automatically selected: <input type = "text" id = "text1" name = "text1" value = "input search keyword" onclick = "javascript: this. form. text1.focus (); this. form. text1.select (); "maxlength =" 15 "/>
From Special Forces-AK47