I know this question was posted a lot and I checked some solutions but none were working perfectly for me.
What I want is to check whether a Stringinput in a TextField is valid or not. Valid entries are only positive integers, in other words everything that is >=0 and an integer.
I tried a solution something like this that I found:
try {
int input = Integer.valueOf(fieldwaitAfterAction.getText());
if(input < 0)) {
validInput = false;
} else {
validInput = true;
}
} catch(NumberFormatException e) {
validInput = false;
}
Works for most of the wrong patterns fine, but if I enter something like '+0' or '-0' it passes through which shouldn't be actually the case. So I want a pure integer number without any characters at the beginning, in between or at the end.
What would the best solution be for this problem?
Thanks a lot!