I have a Dialog that accepts user input, and I want them to only be able to enter positive doubles only.
I tried adding a TextFormatter to the TextField in the initialize method of my controller class. Right now, it's not allowing me to input anything. I'm not sure if it's the TextFormatter that I used wrongly, or it's the regex. I tried a couple of regexes I found online, but nothing seems to work. Here's what I have tried so far:
/\(?[\d.]+\)?/
/\\d+\\.\\d+/
/\\(?[\\d.]+\\)?
Here is the code I added to the initialize method in my controller class.
public void initialize() {
amount.setTextFormatter(new TextFormatter<Object>(change -> {
if (!change.getText().matches("/\\(?[\\d.]+\\)?/")) {
change.setText("");
}
return change;
}));
}
I'm not familiar with regexes as well, so I may not be aware that the ones I've used are completely wrong.
Thanks in advance.
Edit: I rewrote the question to follow the community guidelines. Sorry for posting a terrible question.