0
//Only Allow Numeric Data Types in Hard Drive TextField
        txtPurchaseCost.setOnKeyTyped(e -> {
            char input = e.getCharacter().charAt(0);
            if (Character.isDigit(input) != true) {
                e.consume();
            }
        });

Currently have this code that allows me to only allow numeric values into my TextField. Was wondering how I can make it so I can also allow decimals so the number is in currency format (201.21, 122.00, 12,122.12)

Also thousands separators and only allowing two decimal places would be great but not really important

Adam
  • 37
  • 2
  • 8
  • I would recommend [this solution](https://stackoverflow.com/questions/40472668/numeric-textfield-for-integers-in-javafx-8-with-textformatter-and-or-unaryoperat/40472822) using text formatter. – Jai Apr 27 '18 at 07:42
  • 2
    Why not using a Spinner with the opportune ValueFactory? https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Spinner.html – kekolab Apr 27 '18 at 09:59

0 Answers0