title: JavaScript to allow only numbers, comma, dot, backspace
body: <p>i wrote a javascript function to allow only numbers, comma, dot like this</p>
  
  <pre><code>function isNumber(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();
                }
  
  }
  </code></pre>
  
  <p>but if i want to remove any number form text box.. backspace is not working. then i changed regex code as  "<code>var regex = /^[0-9.,BS]+$/;</code>"</p>
  
  <p>still i am not able to use backspace in textbox.even i cant use left and right keys on textbox is i am doing wrong? can anyone help... thanks. (when I used "BS" in regex instead of backspace its allowing "B","S" Characters in textbox..)</p>