Limiting phone Keyboard Input Length

I m tryng to limit the length of name string a player can enter via the keyboard…I have tried…

if (keyboard)
    {
        inputText = keyboard.text;
        UserNameDisplay.guiText.text=keyboard.text;
        
        if (inputText.length>5)
        {
        	inputText.length=5;
        }
    }

…but .length is a read only attribute.
Any ideas?
cheers

Yes annoyingly. I did it by trimming the return string which is a bit unfriendly for the user.

Hmm so that way they would type in something like…

‘Mad as sticks’

.then hit done and their name would display as…

‘Mad as s’

…hmm.
Well I guess if its the only way…

Here’s how I do it. Limits the amount of text in the input field of the keyboard and the length of the “theName” string to 16 characters. The user can type more than 16 chars and they show in the input field of the keyboard for a sec but any chars that make the text length > 16 disappear right quick. I’d rather have a hard limit so they couldn’t type any more in once the desired length had been hit but I couldn’t figure that out.

private var kb : iPhoneKeyboard;
private var theName : String = "Enter your name";

function Update()
{
	if (kb)
	{
		if (kb.active)
		{
			if (kb.text.length > 16)
			{
				kb.text = kb.text.Substring(0, 16);
			}
			
			theName = kb.text;
		}
		
		if (kb.done) { kb = null; }
	}
}


function OnGUI()
{
   if (GUI.Button(Rect(8, 8, 128, 32), "Keyboard"))
   {
      kb = iPhoneKeyboard.Open(theName, iPhoneKeyboardType.Default);
   }

   GUI.Label(Rect(86, 55, 128, 22), theName);
}

thanks dude :slight_smile: