I have a regex to allow only numbers, numbers with dot and comma, if user inputs character that breaks the regex it should not be typed in:
valueTextBox.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
String input = valueTextBox.getText();
if (!input.matches("\\d+(?:[.,]\\d+)?")) {
}
}
});
For example, I typed 123 initially, then type a dot that should be ok, and I type a number to complete it like 123.123 should be ok, if I type a comma now that should not be ok.