title: Javascript regex to match correct price value
body: <p>Following is my javascript code which only accept number and dot (.). But If I write 123.....122 It's still accept. Basically I'm doing this for price field validation where user can only write this format. </p>
  
  <p><strong>Desire Format:</strong></p>
  
  <pre><code>$(currency)12345(amount).(dot only once)123(decimal)
  </code></pre>
  
  <p><strong>Javascript Code:</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function validate(evt) {
    var theEvent = evt || window.event;
    var key = theEvent.keyCode || theEvent.which;
    key = String.fromCharCode( key );
    var regex = /[0-9]|\./;
    if( !regex.test(key) ) {
      theEvent.returnValue = false;
      if(theEvent.preventDefault) theEvent.preventDefault();
    }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Html Input field:</strong></p>
  
  <pre><code>&lt;input type='text' onkeypress='validate(event)' /&gt;
  </code></pre>
  
  <p>How can I fix this javascript code ?<br>
  Thanks. </p>