Is it possible to limit the size of a number in an InputField?

Hello, I would like to know if there is a way to put a limit to the size of a number in an InputFiel. For example, the highest number = 30. I do not mean the number of digits … if I try to write 31, that is not possible. I think I explain myself;) I appreciate your reply.

Check out InputField documentation… there are a few different ways to validate. What you want would probably need to live-observe the value every Update() and when it became invalid, simply instantly restore it to the previous valid value.

Thanks for your prompt reply, as always. But I have not found anything about it in the Unity documentation, by the way, it is difficult to get clear results in searches.

I don’t think there would be any… it’s just simple data validation.

In Update():

  • keep track of what it was the previous frame (in a string)

  • every time it is different, validate it: decide is this good?

  • if yes, take this value as the previous

  • if not, restore what is in the InputField from the previous frame

It doesn’t get any simpler than that!

1 Like