I don't know how everyone implements it?
1. if Javascript control is used, you can enter multiple decimal places under Firefox,
2. If the regular expression is used for control.
Onkeypress = "If (/[-]? \. \ D $/. Test (value) event. returnvalue = false"
This is also incorrect in Firefox.
So depressing.
Please give us some suggestions. It is best to use regular expressions to be compatible with IE and ff.
Some people say that the match is used, and the test match is not used. It will be displayed correctly under ff, but it cannot be used even if it has been tried,
Looking forward to your solutions
Many of them are wrong on the Internet. It's really wrong,
Another one, written in this way, cannot be guaranteed to be correct ^ ([0-9] + \. [0-9] {2}) | ([0-9] * [1-9] [0-9] *) $
2. ^ ([1-9] \ D *) | 0) (\. \ D {2 })? $
Let's look at what someone else wrote.
Function istridecimal (value ){
If (value! = NULL & value! = ''){
VaR decimalindex = value. indexof ('.');
If (decimalindex = '-1 '){
Return false;
} Else {
VaR decimalpart = value. substring (decimalindex + 1, value. Length );
If (decimalpart. length> 2 ){
Return true;
} Else {
Return false;
}
}
}
Return false;
} <SPAN class = hilite1> input </span> name = "sumadjust" type = "text" id = "sumadjust" size = "20" value = '<C: out value = "$ {form1.sumadjust}"/> 'onkeyup = "If (isnan (value) | istridecimal (value) Execcommand ('undo ') "onafterpaste =" If (isnan (value) | istridecimal (value) Execcommand ('undo ') "/>
Function istridecimal (value ){
If (value! = NULL & value! = ''){
VaR decimalindex = value. indexof ('.');
If (decimalindex = '-1 '){
Return false;
} Else {
VaR decimalpart = value. substring (decimalindex + 1, value. Length );
If (decimalpart. length> 2 ){
Return true;
} Else {
Return false;
}
}
}
Return false;
}
<SPAN class = hilite1> input </span> name = "sumadjust" type = "text" id = "sumadjust" size = "20" value = '<C: out value = "$ {form1.sumadjust}"/>'
Onkeyup = "If (isnan (value) | istridecimal (value) Execcommand ('undo ')"
Onafterpaste = "If (isnan (value) | istridecimal (value) Execcommand ('undo ')"
/>