title: validate amount field using javascript
body: <p>i been looking everywhere for a solution but nothing which quiet matches my criteria.</p>
  
  <p>i want to enable the user to input any positive numbers with (optional 2 decimal places separated by a dot '.')</p>
  
  <p>i.e: 1.23, 12.23, 123.23, 1234.23, 1, 0</p>
  
  <p>how can i do this?</p>
  
  <p>i attempted to use this regex </p>
  
  <pre><code>$('form').submit(function(){
  
          var amount = $('#amount');
          var regex = new RegExp("^\d+(\.\d{1,2})?$");
  
          var error = 0;
  
          if(amount.val() == '' || amount.val() &lt;= 0 || regex.test(amount.val()) == false){
              $('label', amount.parent()).addClass('error');
              error++;
          }else{
              $('label', amount.parent()).removeClass('error');
          }
  
          if(error &gt; 0){
              return false;
          }
  
      });
  </code></pre>
  
  <p>i am not very experienced with regex, and attempted to use the code above which i found through my search but it doesn't seem to work and i don't know why. i am not sure if it is an error in the regex or the way i am using it.</p>