title: Validation of numbers with decimal values in textbox using javascript
body: <p>how to restrict user to enter only numbers with 6 digits and two decimal values in textbox using javascript??</p>
  
  <pre><code>//Function to allow only numbers to textbox
  function validate(key) {
      //getting key code of pressed key
      var keycode = (key.which) ? key.which : key.keyCode;
      var phn = document.getElementById('txtPhn');
      //comparing pressed keycodes
      if ((keycode &lt; 48 || keycode &gt; 57)) {
          return false;
      } else {
          if (phn.value.length &lt; 6) {
              return true;
          } else {
              return false;
          }
      }
  }
  </code></pre>
  
  <p>EDIT: </p>
  
  <pre><code>var txtBudget = document.getElementById('MainContent_txtBudget');
      txtBudget.addEventListener('input', function (prev)
       {
          return function (evt) {
              if (!/^\d{0,6}(?:\.\d{0,2})?$/.test(this.value)) {
                  this.value = prev;
              }
              else {
                  prev = this.value;
              }
          };
      } (txtBudget.value), false);
  </code></pre>