Best way to use newTextField for numbers?

Hi,

I would like a user to input numbers into my TextField, and wondered what the best way to validate this would be. 

I know i can set the field to inputType numbers, but then the keyboard gets stuck on the screen, it also doesn¨t seem to allow numbers with decimals. (like 4.5).

I would really prefer to use the normal userInput and then validate that it¨s a number when im getting the userfield.text value and put it in a variable. (for then to use it in caluculations)

Any idea on how to best achieve this?

Thanks

Hi @Zeatech,

The Lua “tonumber” function should determine if it’s a valid number (as in, can be converted to a number, or nil if it can’t).

Brent

Hi Brent,

Thanks a lot. That worked like charm :slight_smile:

Hi @Zeatech,

The Lua “tonumber” function should determine if it’s a valid number (as in, can be converted to a number, or nil if it can’t).

Brent

Hi Brent,

Thanks a lot. That worked like charm :slight_smile: