Not allow more than 5 digits after decimal. in on javascript "OnKeyUp"?

Posted by James123 on Stack Overflow See other posts from Stack Overflow or by James123
Published on 2010-05-05T20:42:06Z Indexed on 2010/05/06 0:18 UTC
Read the original article Hit count: 158

Filed under:
|

I have a javascript code for textbox that will put commas on in digits like (11,23,233)

 mTextbox.Attributes.Add("OnKeyUp", "javascript:this.value=Comma(this.value);")

function Comma(Num) {

        Num += '';
        Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
        Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
        x = Num.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1))
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        return x1 + x2;
    } 

Now same here I need to restrict user to enter not morethan 5 digits after decimal (ex:

Allow: 12,23,221.34323

Not Allow: 12,23,232.232423

I can change above javascript to work that?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ASP.NET