Restrict the user to enter invalid numbers and decimal places, leading to poor price calculation.CodeFor more information, see.
< Html >
< Head >
< Title > Text number </ Title >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charset = GBK" >
</ Head >
< Script Type = "Text/JavaScript" >
Function Check (event ){
VaR E = Window. Event | Event;
VaR Target = E. srcelement | E.tar get;
VaR K = E. keycode;
If (Isfunkey (k )){
Return True ;
}
VaR C = Getchar (k );
If (Target. value. Length = '' && (C = ' - ' | C = ' + ' )){
Return True ;
}
If (Isnan (target. Value + Getchar (k ))){
Return False ;
}
Return True ;
}
Function Isfunkey (CODE ){
// 8 --> backspace
// 35 --> end
// 36 --> Home
// 37 --> left arrow
// 39 --> right arrow
// 46 --> Delete
// 112 ~ 123 --> F1 ~ F12
VaR Funkeys = [ 8 , 35 , 36 , 37 , 39 , 46 ];
For ( VaR I = 112 ; I <= 123 ; I ++ ){
Funkeys. Push (I );
}
For ( VaR I = 0 ; I < Funkeys. length; I ++ ){
If (Funkeys [I] = Code ){
Return True ;
}
}
Return False ;
}
Function Getchar (k ){
If (K > = 48 && K <= 57 ){
Return String. fromcharcode (k );
}
If (K > = 96 && K <= 105 ){
Return String. fromcharcode (K - 48 );
}
If (K = 110 | K = 190 | K = 188 ){
Return " . " ;
}
If (K = 109 | K = 189 ){
Return " - " ;
}
If (K = 107 | K = 187 ){
Return " + " ;
}
Return " # " ;
}
</ Script >
< Style Type = "Text/CSS" >
Textarea {
Width : 200px ;
Height : 80px ;
}
Span {
Color : # Ff0000 ;
}
</ Style >
< Body >
< Input Style = "Ime-mode: Disabled ;" Onpaste = "Return false" Onkeydown = "Return check (event )" Onkeyup = "If (isnan (this. Value) | this. value <0 | this. value> 59) This. value = '0 '" >
</ Body >
</ Html >
Text number