money input mask

Discussion in 'JavaScript' started by gigamike, Aug 7, 2008.

  1. #1
    Guys,

    Anyone has a javascript code wherein it allows the textbox to enter only decima(12,2). So in short his only allowed to enter numeric and dot with a maximum length of billion 999999999999.99 and 99999999999999 (15 integers) is not allowed

    Thanks,

    Mike
     
    gigamike, Aug 7, 2008 IP
  2. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think this will work for you, only thing I wasn't too sure about is the decimal. In this regex there has to be a decimal and at least 1 number eg. 100 is "false" but 100.0 is "true" ...

    
    <html>
    <head>
    <script language="javascript">
    function checkval(mynum) {
    var re = /[0-9]{1,12}\.[0-9]{1,2}/.test(mynum);
    alert(re);
    // if re is false then etc etc 
    }
    </script>
    </head>
    <body>
    <input onblur="checkval(this.value);"></input>
    </body>
    </html>
    
    Code (markup):
     
    mallorcahp, Aug 7, 2008 IP