You can only enter numbers and delete values that are not numbers (copied values cannot be filtered)
<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)
<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.
<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
<Input type = text t_value = "" o_value = "" Export nkeypress = "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 "encode nkeyup =" 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 "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
<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.
<Input parameter nkeyup = "value = value. Replace (/[^ \ W \. \/]/ig, ''')">
6. Only numbers and English letters can be entered. <font color = "red"> Chun </font>
<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:
<Input parameter nkeypress = "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 parameter nkeyup = "this. value = This. value. replace (/^ (\-) * (\ D + )\. (\ D ). * $/, ''$1 $2. $3 '')">
From: http://blog.csdn.net/ydy277163648/article/details/8433737