How to make text box only accept numbers?

I think the cleanest way to validate is to do it OnTextChanged - this keeps your input box from getting crowded before commit.

Here’s how I did it:




        // Define this lambda in [YourWidget]::Construct()
        auto fnOnTextChanged = =](const FText& Val)
        {
            if (!Val.IsNumeric()){  // Returns false if the text is not completely numeric

                auto chopped = FText::FromString(Val.ToString().LeftChop(1));  // This gets rid of the last character in the text
                TextPtr->SetText(chopped);  // Set the text (you have to cache/SAssignNew the SEditableTextBox for this to work)
            }
        };

       // Bind the lambda to your widget
       // ChildSlot]...
        SAssignNew(TextPtr, SEditableTextBox)
       .OnValueChanged_Lambda(fnOnTextChanged)