-2

I want the value we write in the textfield to be alphabetical only. It should not accept numeric values.How can I do that ?

I tried this codes but it is not working.

@FXML
    void keyEventTextFieldSend(KeyEvent keyEvent){
        Pattern pattern = Pattern.compile("^\\p{Alpha}+$");
        textField.textProperty().addListener((ov, oldValue, newValue) -> {
            Matcher matcher = pattern.matcher(newValue);
            if(matcher.matches())
                textField.setText(newValue.toUpperCase());
        });

    }
mcz
  • 13
  • 2
  • 5
    do some research before asking please.. you want to use a textformatter. plus: work through a tutorial about how to use event handlers: your snippet looks like you add a handler multiple times (on every key received) which you __must not__ – kleopatra May 28 '22 at 18:01

0 Answers0