I would like to check my inputted string on a comma, which is pretty easy ( just used this: How can I check if a single character appears in a string?). Now I want to check if a character is present more than once. (in this case a comma (/u002C)) I have created this code:
public static void addTextLimiterDouble(final TextField tf, final int maxLength, final Button submitButton) {
tf.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(final ObservableValue<? extends String> ov, final String oldValue, final String newValue) {
if (oldValue.contains("\u002C") && newValue.endsWith("\u002C")) {
tf.setText(oldValue);
}
}
});
This gives a StackOverflow error, because it seems it can not get out of the loop. Can anyone explain why it can't?
Note: I know there are maybe more ways to check for more than one character, but I am just curious why this gives me an error.
Any help is greatly appreciated!