On Apr 28, 8:29 pm, Graham J <[email protected]> wrote: > I had some input checking going on with the old KeyListener interface > that would cancelKey() the event if the input was not a digit. > > I'm trying to convert that over to use a KeyDownHandler, but I can't > figure out how to check if they key is a digit. > > This is the closest I've got: > > public void onKeyDown(KeyDownEvent event) > { > int keyCode = event.getNativeKeyCode(); > if (!Character.isDigit(keyCode) > { > // TextBox.cancelKey() suppresses the current keyboard event. > ((TextBox) event.getSource()).cancelKey(); > } > > } > > The catch is, Character.isDigit(int) is not emulated in GWT -- it only > accepts a char parameter. > > So, how do I convert the keyCode to a char, or, check isDigit() on the > keyCode? Or an entirely different method? IS getNativeKeyCode() the > right approach for this?
No, because you'll have the same keyCode whether the key was typed with Shift pressed or not, and you'll have different keyCode for the keypad. And you can just cast your int to a char, it should work in 99.9% of cases; or you could use "'0' <= c && c <= '9'" instead, where 'c' can be an int. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
