Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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.