title: dynamically set length of an input type textbox in jquery or javacscript
body: <p><strong>Get maximum 13 numbers in an input type text box but if user presses 14 number as decimal, only then it should allow maximum 16 numbers.</strong></p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;input type="text" maxlength="15" onkeyup="checkCurrency(this)"/&gt;
  </code></pre>
  
  <p><strong>script:</strong></p>
  
  <pre><code>    function checkCurrency(ctrl) {
          ctrl.setAttribute('maxlength', '16');
          var currency = ctrl.value.replace(/[,]+/g, '');
          var valid = /^\d{0,13}(\.\d{0,2})?$/.test(currency),
          val = currency;
          if (valid) {                
              ctrl = val;
          } else {             
              ctrl.setAttribute('maxlength', '13');                
          }
      };   
  </code></pre>
  
  <p>Now, it works fine when 14th place is a decimal(.),but please put any integer on 14th place and see the difference.</p>