Amount input Box controls a valid number with only two digits after the decimal point

Source: Internet
Author: User

<% @include file= "/web-inf/jsp/common/common.jsp"%><title> price entry limit </title><script type= "text/ JavaScript ">/*** Real-time dynamic force change user input * arg1 inputobject **/function Amount (th) {var regstrs= [[' ^0 (\\d+) $ ', ' $ '),//prohibit entry of the whole number of parts more than two, but the first 0[' [^\\d\\.] +$ ', '],//prohibit entry of any non-digital and point[ ‘\\. (\\d?) \\.+ ', '. $ '],//prohibit entry of more than two points[' ^ (\\d+\\.\\d{2}). + ', ' $ ']//prohibit entry of more than two decimal places "original"        ];  for(i = 0; i < regstrs.length; i++) {var reg=NewREGEXP (regstrs[i][0]); Th.value= Th.value.replace (Reg, regstrs[i][1]); }    }    /*** After inputting, input mode loses focus and then makes judgment and force change, and 0 complement of decimal point * arg1 Inputobject * This function is very silly, I wrote it long ago, no optimization, but the function is very complete, you try to use     * There's actually a faster JavaScript built-in function that can extract numbers from clutter: * parsefloat (' 10 '); **/function Overformat (th) {var v=Th.value; if(v = = "") {            //v = ' 0.00 ';v = "; } Else if(v = = = ' 0 ') {            //v = ' 0.00 ';v = "; } Else if(v = = = ' 0. ')) {            //v = ' 0.00 ';v = "; } Else if(/^0+\d+\.? \d*.*$/. Test (v)) {v= V.replace (/^0+ (\d+\.? \d*). *$/, ' $ '); V=Inp.getrightpriceformat (v). Val; } Else if(/^0\.\d$/. Test (v)) {v= v + ' 0 '; } Else if(!/^\d+\.\d{2}$/. Test (v)) {            if(/^\d+\.\d{2}.+/. Test (v)) {v= V.replace (/^ (\d+\.\d{2}). *$/, ' $ '); } Else if(/^\d+$/. Test (v)) {v= v + '. 00 '; } Else if(/^\d+\.$/. Test (v)) {v= v + ' 00 '; } Else if(/^\d+\.\d$/. Test (v)) {v= v + ' 0 '; } Else if(/^[^\d]+\d+\.? \d*$/. Test (v)) {v= V.replace (/^[^\d]+ (\d+\.? \d*) $/, ' $ '); } Else if(/\d+/. Test (v)) {v= V.replace (/^[^\d]* (\d+\.? \d*). *$/, ' $ '); Ty=false; } Else if(/^0+\d+\.? \d*$/. Test (v)) {v= V.replace (/^0+ (\d+\.? \d*) $/, ' $ '); Ty=false; } Else {                //v = ' 0.00 ';//set default values when the user is not enteredv = "; }} Th.value=v; }</script>OnBlur= "Overformat (this)"/></body>

Amount input Box controls a valid number with only two digits after the decimal point

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.