Js restricts input to only numbers, letters, and Chinese characters.
Js restricts that input can only be a number or a decimal point, or only a number or a decimal point, etc. This article has roughly sorted out some items and interested friends can add them to their favorites.
The Code is as follows:
<Input type = "text" onKeyUp = "this. value = this. value. replace (/[^. d]/g, ''); if (this. value. split ('. '). length> 2) {this. value = this. value. split ('. ') [0] + '. '+ this. value. split ('. ') [1]} ">
1. Only numeric code can be entered in the text box (decimal point cannot be entered)
The Code is as follows:
<Input parameter nkeyup = "this. value = this. value. replace (/D/g, ''') "using nafterpaste =" this. value = this. value. replace (/D/g, ''') ">
2. Only numbers can be entered, and decimal points can be entered.
The Code is as follows:
<Input parameter nkeyup = "if (isNaN (value) execCommand (''undo'') "using nafterpaste =" if (isNaN (value )) execCommand (''undo '')">
<Input name = txt1 then nchange = "if (/D /. test (this. value) {alert (''can only enter numbers''); this. value = ''';} ">
3. Number and decimal point method 2
The Code is as follows:
<Input type = text t_value = "" o_value = "" Export nkeypress = "if (! This. value. match (/^ [+-]? D *?.? D *? $/) This. value = this. t_value; elsethis. t_value = this. value; if (this. value. match (/^ (? : [+-]? D + (? :. D + )?)? $/) This. o_value = this. value "encode nkeyup =" if (! This. value. match (/^ [+-]? D *?.? D *? $/) This. value = this. t_value; elsethis. t_value = this. value; if (this. value. match (/^ (? : [+-]? D + (? :. D + )?)? $/) This. o_value = this. value "returns nblur =" 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
The Code is as follows:
<Input parameter nkeyup = "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.
Copy the Code as follows:
<Input parameter nkeyup = "value = value. replace (/[^ w./]/ig, ''')">
6. Only numbers and English letters can be entered.
The Code is as follows:
<Input parameter nKeyUp = "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:
The Code is as follows:
<Input parameter nKeyPress = "if (event. keyCode <48 | event. keyCode> 57) & event. keyCode! = 46 |/. dd $/. 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:
The Code is as follows:
<Input parameter nkeyup = "this. value = this. value. replace (/^ (-) * (d + ). (dd ). * $/, ''$1 $2. $3 '')">