javafxjava-8controlsfx

ControlsFX TextField validation


How can I validate the text field to be contained only float values using ControlsFX validator?

TextField price = new TextField();
ValidationSupport validationSupport = new ValidationSupport();

Solution

  • Please, read this documentation

    All you need to do is this type of code where you bind validator with TextField:

    ValidationSupport validationSupport = new ValidationSupport();
    validationSupport.registerValidator(textField, Validator.createEmptyValidator("Text is required"));
    

    Instead of Validator.createEmptyValidator you have to create validator using Regex expresion / Pattern like this: ^[-+]?[0-9]*\.?[0-9]+$

    Then you can validate your text.