3
I am trying to create a specific field for UF, in which only 2 capital letters will be allowed. I tried to use regular expression, but I couldn’t. Could someone give me a helping hand?
public class CampoUF extends TextField {
public CampoUF() {
textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (!newValue.matches("\\W*")) {
//setText(newValue.replaceAll("[^\\W]", ""));
setText(newValue.toUpperCase());
}
}
});
}
Thanks for the help ! Plus, it is not necessary to use any "regex" to block the numbers ?
– G1Win
@G1win No need to use regex. I’m already editing the answer.
– Victor Stafusa
@G1win Response edited.
– Victor Stafusa
Thank you very much !
– G1Win