title: Input box onchange only allow numbers and one dot
body: <p>I am creating an input box with an onChange function that will check to see if the characters are only digits and only allow up to one period/dot '.'</p>
  
  <p>The function I have here is not working:</p>
  
  <pre><code>function addPercentSeparator(n) {
    let str = n;
    let match = str.match(/\d*\.\d*/)
    if (match) {
      return str;
    }
  }
  </code></pre>
  
  <p>I also tried: <code>let match = str.match(/^([0-9]+(\.[0-9]+)?)/)</code></p>
  
  <p>What I am trying to achieve is only allowing for one period.
  If the user enters a number without a period, it will append a period to end of string when they click outside the input box.</p>