Restricting user from typing non numeric characters in text field

I am very new to Vaadin programming. I need help in restricting users from entering non numeric characters into a text field.
Restriction should be applied when the user tries to enter the non numeric characters.

This is actually one of the exercises in the Vaadin Advanced course! :slight_smile:

You have to do it with GWT; extend the text field widget and register a KeyDownHandler. In the handler, check what key was pressed, and reject the event if the key isn’t a number (or enter, backspace, etc.).

Thanks Thomas this really helped :slight_smile:

Is there really no simple built-in solution for such a common task that belongs to the heart of the ajax philosophy? Sometimes I can’t believe Vaadin has matured for so many years.

I’m not sure I agree with the ‘heart of the Ajax philosophy’ part, but the solution is really quite simple, even if it involves GWT. Most of the time, users don’t want to restrict textfield input. Validation, sure, but not actually blocking input of a certain type. Even if they would, few developers want to restrict the exact same thing. The way the TextField is implemented follows the 99% case, with extremely simple modification necessary for the 1% case; I don’t really see the issue here.