Hello Derek,
I asked this question before, so I got it working with the help of our fellow forum members.
So the code goes like this:
-- This section happens when the user types -- Lets set up a max length, compare it and if too long, replace it local myNum = 10 -- max characters if string.len(event.text) \> myNum then -- Text too long, replace textField text with old text TextField.text = event.oldText -- change the "TextField" with the --name of your textfield print ("max length reached") end
you should put this block of code in the “editing” phase of the textbox
this code restricts any inputs when the string reached it’s limit, and goes back to the last string that the user typed before it reaches the string limit.
if you want a alert that says that the string limit has been reached call this function after the "print ( “max length reached”)
local function checkIfBlank() local alert = native.showAlert ( "Limit reached", "I will not accept it", {"Ok"}, ) end
Hope it helps,
Goodluck,
Jam