using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;

public class SubmitWindow : MonoBehaviour {
	
	TextMesh _name;
	string _input = "";
	// Use this for initialization
	void Start () {
		_name = transform.FindChild("Name").GetComponent<TextMesh>();
	}
	
	public void Finish()
	{
	
	}
	
	// Update is called once per frame
	void Update () {
		_name.text = _input;
		
		if (Input.inputString == "\b") 
		{
			if(_input.Length > 0)
				_input = _input.Substring(0, _input.Length - 1);
    	}
		else
			_input += Input.inputString;
		
			_input = Regex.Replace(_input, @"[^a-zA-Z0-9 ]", "");
	    	_input = Regex.Replace(_input, "^[ ]+|[ ]+$|([ ](?=[ ]+))", "");
	    	_input = _input.Replace(" ", string.Empty);
			_input = _input.Substring(0, Mathf.Min(_input.Length, 12));
		Globals.Name = _input;
	}
}
