text input

How can i handle the maximum of characters, that user has entered from keyboard on native.newTextField?

 

Use string.len() to get the number of characters the user entered with a runtime listener.

[lua]

function checkMaxChar()

            local maxChar = 10

            if string.len(event.text) <= maxChar then

                – Do something

                print(" String is less or equal to 10 char")

            else

                – tell user input text is too long with an alert…etc

                print(" String is too long")

            end

            

       

end

Runtime:addEventListener(“enterFrame”, checkMaxChar)

[/lua]

or if you just want to check the maxChar at the “submitted” phase then you could just

[lua]

if string.len(event.text) <= maxChar then

    – string is good, do something with it

else    

    – string is too long, fix it, show an alert, clear the textfield or something…

end

[/lua]

Thank you, will try it!

Use string.len() to get the number of characters the user entered with a runtime listener.

[lua]

function checkMaxChar()

            local maxChar = 10

            if string.len(event.text) <= maxChar then

                – Do something

                print(" String is less or equal to 10 char")

            else

                – tell user input text is too long with an alert…etc

                print(" String is too long")

            end

            

       

end

Runtime:addEventListener(“enterFrame”, checkMaxChar)

[/lua]

or if you just want to check the maxChar at the “submitted” phase then you could just

[lua]

if string.len(event.text) <= maxChar then

    – string is good, do something with it

else    

    – string is too long, fix it, show an alert, clear the textfield or something…

end

[/lua]

Thank you, will try it!