I'm trying to create a specific field for UF, where only 2 uppercase letters will be allowed. I tried using regular expression, but I could not. Could someone help me?
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());
}
}
});
}