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#


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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