Setting The Limit Of The Number Of Characters In Textfield And Removing The Text From The Textfield On Clicking The Box

I am using a textfield in my project i want to set the limit of the number of characters that can be entered in the textfield. i’m unable to do that. can anybody tell me how can i do that?? Secondly, when i click the textbox i want the old text to be removed. how can i do that? i’m posting the code. 

[lua]

local function onTitle( event )

    – Hide keyboard when the user clicks “Return” in this field

    if ( “ended” == event.phase or “submitted” == event.phase ) then

        titletext = event.target.text

         print(titletext)

        native.setKeyboardFocus( nil )

    end

end

title = native.newTextField( display.contentWidth*0.04, display.contentHeight-(display.contentHeight*0.90), 350, 50,

       onTitle )

–title.x = title.width * 0.5

title.text = “Enter Title”

title.isEditable = true

group:insert(title)

[/lua]

Check string length in event.phase == “editing” in your native box handler. If it’s too long set event.text = substring(event.text,maxlength).

So something like this:

if event.phase == "editing" then local txt = event.text if(string.len(txt)\>9)then txt=string.sub(txt, 1, 9) event.text=txt end end

Check string length in event.phase == “editing” in your native box handler. If it’s too long set event.text = substring(event.text,maxlength).

So something like this:

if event.phase == "editing" then local txt = event.text if(string.len(txt)\>9)then txt=string.sub(txt, 1, 9) event.text=txt end end

thanks it worked :slight_smile:

thanks it worked :slight_smile:

thnx , will be using this :smiley:

thnx , will be using this :smiley: