0

I have the folling code, when it triggers the tab key is not working in firefox but works in chrome.

HTML:

<input id="contactPhone" onkeypress="validationPhone(event)" data-bind='value: phone' type="text" class="form-control" maxlength='10'>

Here is the JS code:

  validationPhone = function (x) {
      var evt = window.event || x;

      if ((evt.which > 46 && evt.which < 58) || evt.which == 8) {
          return true;
      }
      else {
          evt.preventDefault();
      }
  }
user2281858
  • 1,957
  • 10
  • 41
  • 82
  • 1
    See this for why it won't work on firefox http://stackoverflow.com/questions/4471582/javascript-keycode-vs-which – Yvo Cilon Jul 27 '16 at 09:15

1 Answers1

0

you are using Javascript Char Code , You can use char code 9 for tab and Instead of onkeypress use onkeydown event

Try With this :

HTML:

<input id="contactPhone" onkeydown="validationPhone(event)" data-bind='value: phone' type="text" class="form-control" maxlength='10'>

JS:

validationPhone = function (x) {
  var evt = window.event || x;

  if ((evt.which > 46 && evt.which < 58) || evt.which == 8 ||evt.which == 9) {
      return true;
  }
  else {
      evt.preventDefault();
  }

}

B N Palei
  • 1
  • 2