I want to control the input into a Javafx TextField so that I can allow only Numeric input, and so that if the max characters are exceeded, then no change will be made to th
Try this solution add this function in your controller , you must add it on the keyPressed Action of your text field.
@FXML
void verifnum(KeyEvent event) {
txt.textProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends String> observable, String oldValue,
String newValue) {
if (!newValue.matches("\\d*")) {
txt.setText(newValue.replaceAll("[^\\d]", ""));
}
}
});
}