title: Limiting input field to one decimal point and two decimal places
body: <p>I have an input field which is limited to 6 characters.  How can I validate my input field so that a user can't put more than one decimal point (i.e. 19..12), plus it can only be to two decimal places as well (i.e. 19.123)?</p>
  
  <p>This is my input field</p>
  
  <pre><code>&lt;input type="text" name="amount" id="amount" maxlength="6" autocomplete="off"/&gt;&lt;span class="paymentalert" style="color:red;"&gt;&lt;/span&gt;
  </code></pre>
  
  <p>Here is my validation script.</p>
  
  <pre><code>$(function(){
  $("#amount").keypress( function(e) {
      var chr = String.fromCharCode(e.which);
      if (".1234567890NOABC".indexOf(chr) &lt; 0)
          return false;
  });
  });
  
  $("#amount").blur(function() {
      var amount = parseFloat($(this).val());
      if (amount) {
          if (amount &lt; 40 || amount &gt; 200) {
              $("span.paymentalert").html("Your payment must be between £40 and £200");
          } else {
              $("span.paymentalert").html("");
          }
      } else {
          $("span.paymentalert").html("Your payment must be a number");
      }
  });
  </code></pre>
  
  <p>Jonah</p>