How to prevend GUI.Textfield allow Multiline Strings?

Im using a Gui.Textfield as an input Textfield.

In the reference they write it is a single Line Textfield. But it still allows a " " as input.

Do i miss something, or do i have to use a Regular Expression or String.replace(" ", "") to prevent the String to be Multilined?

Or is there even a better way?

var stringToEdit = "Hello World";

function OnGUI () {
// Make a text field that modifies stringToEdit.
stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 25);
}

http://unity3d.com/support/documentation/ScriptReference/GUI.TextField.html

I noticed that : GUI.Textfield only becomes multilined when you add the “maxLength” value (in your case : 25)

In my little test, the only way I could get the textfield to have multiple lines is if I set the start string to have a newline in it and don't escape it (either through \ or using the @ syntax).

I tested it with typing in and it didn't create a newline or anything. I'm assuming that it escapes special characters like \.

I got this problem too. But in my case,I set a custom style to TextField. I don't know why it allows multiple lines, my custom style only changed Textures.

The only thing I have found is to use replace string as Case23 said

string compareText = inputString;

inputString = GUILayout.TextField(inputString, 20, randomGuiStyle);

if (compareText != inputString)
{
    // This is the only way I have found to remove new line & carriage return....
    inputString = inputString.Replace("
", "").Replace("\r", "");
}

There is an old post talking about it here http://forum.unity3d.com/viewtopic.php?p=257819 AngryAnt has a good idea(Event.current), but I have not had any luck with it.

If you want more control over the touch keyboard, don’t use a TextField at all. On mobile devices you always have to use the native keyboard which displays it’a own input field above your Unity application. So it’s way easier to replace the TextField with a Button and simply open up the keyboard with the desired settings:

TouchScreenKeyboard