title: Why is my javascript regexp test function not working?
body: <p>I've got a Javascript function that tests a regexp that I'm intending to validate positive decimals up to a precision of two:</p>
  
  <pre class="lang-js prettyprint-override"><code>function isPositiveDecimalPrecisionTwo(str) {
      return /^\d*(\.\d{1,2}$)?/.test(str);
  }
  </code></pre>
  
  <p>I'm not getting the results I'm expecting when I call it from code.</p>
  
  <p>For example:</p>
  
  <pre class="lang-js prettyprint-override"><code>var a = isPositiveDecimalPrecisionTwo("1");         //   expect t, returns t
  var b = isPositiveDecimalPrecisionTwo("1.2");       //   expect t, returns t
  var c = isPositiveDecimalPrecisionTwo("1.25");      //   expect t, returns t
  var d = isPositiveDecimalPrecisionTwo("1.257");     // * expect f, returns t *
  var e = isPositiveDecimalPrecisionTwo("1.2575");    // * expect f, returns t *
  var f = isPositiveDecimalPrecisionTwo(".25");       // * expect t, returns f *
  var g = isPositiveDecimalPrecisionTwo("d");         //   expect f, returns f
  var h = isPositiveDecimalPrecisionTwo("d1");        //   expect f, returns f
  var i = isPositiveDecimalPrecisionTwo("1d");        // * expect f, returns t *
  var j = isPositiveDecimalPrecisionTwo("1d1");       // * expect f, returns t *
  var k = isPositiveDecimalPrecisionTwo("-1");        //   expect f, returns f
  var l = isPositiveDecimalPrecisionTwo("-1.5");      //   expect f, returns f
  </code></pre>
  
  <p>There are three issues:</p>
  
  <ol>
  <li>Validating "1.257" or "1.2575" returns true, which I though would
  return false due to the <code>\d{1,2}</code></li>
  <li>Validating ".25" returns false, which I thought would return true due to the <code>^\d*</code></li>
  <li>Validating "1d" or "1d1" return true. It looks like <code>\.</code> is reading as any character when it looks to me like it's a properly escaped "." (dot).</li>
  </ol>
  
  <p>However, when I use a tool like regexpal.com, the same regexp appears to be validating the way I expect:</p>
  
  <blockquote>
    <p><a href="http://regexpal.com/?flags=g&amp;regex=%5E%5Cd%2B(%5C.%5Cd%7B1%2C2%7D%24)%3F&amp;input=" rel="nofollow">http://regexpal.com/?flags=g&amp;regex=%5E%5Cd%2B(%5C.%5Cd%7B1%2C2%7D%24)%3F&amp;input=</a></p>
  </blockquote>
  
  <p>What am I missing?</p>