I have this piece of code which is supposed to remove any non-character value and replace it with a blank space (it deletes the non-character value)
public void firstNameOnlyText() {
txtFirstName.textProperty().addListener(new ChangeListener<String>() {
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (!newValue.matches("\\D*")) {
txtFirstName.setText(newValue.replaceAll("[^\\D]", ""));
}
}
});
}
The code works perfectly to remove numbers, but I don't know what regex to use so it also replaces punctuations (e.g `, !, ], [ etc.)
Can someone help me?