title: How can I create an input field that allows only numbers and comma and dot?
body: <p>I am using select2. So it is not a real number input field I try to create an input field that allows only numeric with decimal:</p>
  
  <pre><code>&lt;input type="text" name="numeric" class='select2 allownumericwithdecimal'&gt; 
  
   $(".allownumericwithdecimal").on("keypress keyup blur",function (event) {
          $(this).val($(this).val().replace(/[^0-9\.]/g,''));
          if ((event.which != 46 || $(this).val().indexOf('.') != -1) &amp;&amp; (event.which &lt; 48 || event.which &gt; 57)) {
            event.preventDefault();
          }
        });
  </code></pre>
  
  <p>What I need now is, that it allows not only point, it should also allow comma. This is my approach:</p>
  
  <p> </p>
  
  <pre><code> $(".allownumericwithdecimal").on("keypress keyup blur",function (event) {
          $(this).val($(this).val().replace(/[^0-9\.]/g,''));
          if ((event.which != 46 || $(this).val().indexOf('.') != -1 || $(this).val().indexOf(',') != -1) &amp;&amp; (event.which &lt; 48 || event.which &gt; 57)) {
            event.preventDefault();
          }
  </code></pre>
  
  <p>Still no comma allowed..
            });</p>