title: js backspace and counting how many digits
body: <p>i have this code for counting how many digits where entered</p>
  
  <pre><code>var tnnod=0;
  function telephone(e) {
      if (tnnod&lt;10) {
          var key;
          var keychar;
  
          if (window.event) {
              key = window.event.keyCode;
          }
          else if (e) {
              key = e.which;
          }
          else {
              return true;
          }
          keychar = String.fromCharCode(key);
  
  if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
     return true;
  }
  else if ((("0123456789").indexOf(keychar) &gt; -1)) {
      tnnod+=1;
     return true;
  }
  else if (keychar == "-") { 
    return true;
  }
  else
     return false;
  }
      else
          return false
  }
  </code></pre>
  
  <p>but how do i remove 1 from the counter each time the backspace was hitted and the char that was deleted was a digit and not "-"</p>
  
  <p>i have tried getting the key == 8 to do something but hitting the backspace doesn't really return anything for some reason</p>
  
  <p>what can be the problem?</p>