Monday, January 7, 2013

How to only allow digits to be entered in a textbox?

Hi,

I have a textbox where I want to user to only enter digits. Moreover I want to prevent him entering other characters. This is what I tried but it does not work:

    @UiHandler("textbox")
    void onInputsKeyPress(KeyPressEvent event) {
        if (!Character.isDigit(event.getCharCode())) {
            ((IntegerBox) event.getSource()).cancelKey();
        }
    }


Any hints?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/qj6zZvmH9iMJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment