Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

there is a text box on GUI in my application created using Unity3D. in the textbox user can input only the keys of "A-Z", "0-9" , "enter key" , "." and "," other key press should be ignored (not should print in textbox when typing). how to do this in Unity3D C#

share|improve this question

1 Answer 1

I'm assuming you're using GUI.TextField?

It doesn't appear that there's a built-in way to restrict the text field's legal input set, however, you can achieve the validation behavior you want by writing a script:

public class LimitInput : MonoBehaviour {
  public void OnGUI() {
    text = GUI.TextField(..., text);
    text = /* replace offending text here */
  }

  string text = string.Empty;
}

A simple implementation of the replacement might be along the lines of text = text.Replace("!", "") for example (to remove all ! characters). To implement the specifics of your request, you'll probably want regular expressions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.