Text Box price reserved two decimal points

Source: Internet
Author: User

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 ')"
/>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.