I am working with a JavaFX 2.2 project and I have a problem using the TextField control. I want to limit the characters that users will enter to each TextField but I can\'t
I have this bit of code that only allows numbers and limits the input length on a text field in Javafx.
// Event handler for inputPrice
inputPrice.setOnAction(event2 -> {
// Obtain input as a String from text field
String inputPriceStr = inputPrice.getText();
// Get length of the String to compare with max length
int length = inputPrice.getText().length();
final int MAX = 10; // limit number of characters
// Validate user input allowing only numbers and limit input size
if (inputPriceStr.matches("[0-9]*") && length < MAX ) {
// your code here
}});