EasyUI Forum

General Category => Bug Report => Topic started by: anton.dutov on July 09, 2012, 05:51:17 AM



Title: numberbox bug
Post by: anton.dutov on July 09, 2012, 05:51:17 AM
numberbox alloows incorect input like '0.1.1.1.1.1.1'
Previsiosly i posted code wich wiil handle this case
Code:
function num_filter(e/*event*/, o /* object*/) {
  var o = $(o);
  var v = o.val();
  var keyCode = ('which' in e) ? e.which : e.keyCode;
  if ($.inArray(keyCode, [8, 9, 35, 36, 37, 38, 39, 40, 45, 46]) != -1) // Special keys
    return true;
  if (keyCode == 190) { // Dot
    if (v.indexOf('.') == -1) { // no dot in input
      if (v == '') // Val is empty? add '0' (value becomes 0.)
        o.val('0');
      return true;
    }
    return false;
  }
  isNumeric = (keyCode >= 48 /* 0 */       && keyCode <= 57  /* 9 */) ||
              (keyCode >= 96 /* NUMPAD0 */ && keyCode <= 105 /* NUMPAD9 */);
  modifiers = (e.altKey || e.ctrlKey || e.shiftKey);
  return isNumeric || modifiers;
}