title: Javascript restrict input once 2 decimal places have been reached
body: <p>I currently have a number input script that behaves similar to a calculator with the way numbers are displayed, but I want to stop the adding of additional numbers to the series after two numbers past the decimal point.</p>
  
  <p>Here is what I have so far, though the limiting doesn't occur correctly.</p>
  
  <p>It should work like this:</p>
  
  <p>1.25 - Allowed</p>
  
  <p>12.5 - Allowed</p>
  
  <p>125.5 - Allowed</p>
  
  <p>125.55 - Allowed</p>
  
  <p>123.555 - Not Allowed</p>
  
  <pre><code>rText = document.getElementById("resultText");
  
  function selectNumber(num) {
  if (!rText.value || rText.value == "0") {
      rText.value = num;
  }
  else {
  </code></pre>
  
  <p>this part works...</p>
  
  <pre><code>        rText.value += num;
  
      }
    }
  }
  </code></pre>
  
  <p>but this part doesn't work... Any ideas???</p>
  
  <pre><code>if (rText.value.length - (rText.value.indexOf(".") + 1) &gt; 2) {
  
          return false;
      } else {
          rText.value += num;
  
      }
    }
  }
  </code></pre>