title: Numeric validation with RegExp to prevent invalid user input
body: <p>I have a JavaScript function that validates an input field and prevents the user from typing anything that doesn't match the condition. This function is based on <code>event.keyCode</code>.</p>
  
  <p>I'm trying to modify the function to use a RegExp and validates not "per character" but "per whole input" so that it does the same, but with different conditions:</p>
  
  <ol>
  <li>numeric only </li>
  <li>allowed decimal "." or ","</li>
  </ol>
  
  <p>Here is the function in its current form, using <code>event.keyCode</code>:</p>
  
  <pre><code>function isNumeric(evt, alertDIVid, alertMsg) {
      var charCode = (evt.which) ? evt.which : event.keyCode
      if (charCode &gt;= 48 &amp;&amp; charCode &lt;= 57) {
          document.getElementById(alertDIVid).innerHTML = '';
          return true;
      }
      else {
          document.getElementById(alertDIVid).innerHTML = alertMsg;
          return false;
      }
  }
  
  document.getElementById('AMNT').onkeypress = function(event) {
      event = event || window.event;
      return isNumeric(event, 'numericalert', 'Numeric values only!')
  };
  </code></pre>