title: Javascript Regex for Decimal Numbers - Replace non-digits and more than one decimal point
body: <p>I am trying to limit an input to a decimal number. I'd like any invalid characters not to be displayed at all (not displayed and then removed). I already have this implemented but for whole integers (like input for a phone number) but now I need to apply it for decimal input.</p>
  
  <p><strong>Sample input/output:</strong></p>
  
  <pre><code>default value 25.00  -&gt; type 2b5.00  -&gt; display 25.00
  default value 265.50 -&gt; type 2.65.50 -&gt; display 265.50 (as if prevented decimal point from being entered)
  default value 265.52 -&gt; type 265.52. -&gt; display 265.52 (same as previous one)
  </code></pre>
  
  <p><strong>End New Edit</strong></p>
  
  <p>I found many threads that dealt with "decimal input" issue but almost 99% of them deal only with "match"ing and "test"ing the input while my need is to replace the invalid characters.</p>
  
  <p>Other than trying many regexes like <code>/^\d+(\.\d{0,2})?$/</code>, I also tried something like the below which keeps only the first occurrence in the input. This still isn't my requirement because I need the "original" decimal point to remain not the first one in the new input. This was the code for it:</p>
  
  <pre><code>[this.value.slice(0, decimalpoint), '.', this.value.slice(decimalpoint)].join('')
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/4572194/regex-to-replace-everything-except-numbers-and-a-decimal-point">This thread</a> is the closest to what I need but since there was no response to the last comment about preventing multiple decimal points (which is my requirement), it wasn't useful.</p>
  
  <p>Any help would be appreciated.</p>