private char MyValidate(char charToValidate)
{
//Checks if a dollar sign is entered....
if (charToValidate == textChar*)*
{*
// ... if it is change it to an empty character.*
//charToValidate = '\0';*
//*
}*
else*
{*
charToValidate = '\0';*
//index = i ;*
//charToValidate = textChar[i-1] ;*
}*
return charToValidate;*
}* And if he types wrong he is not allowed to type, Like if I need to type"Hello" , and user press ‘e’ key on the start then nothing should happen, User can only type ‘h’ then ‘e’ then ‘l’ … so on, but this seems to be not working for me please Help! iam using unity 5 and its ui inputfield.
If I understand your question properly then following should work. I am using OnValueChange event of InputField.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Validate : MonoBehaviour {
private InputField inputField;
private string expectedString = "Hello";
// Use this for initialization
void Start () {
inputField = GameObject.Find ("InputField").GetComponent<InputField>();
}
// Update is called once per frame
void Update () {
}
public void OnValueChanged()
{
if (inputField.text.Length <= expectedString.Length ) // if length exceeds expectedString then we will remove current char
{
if(inputField.text.Length > 0) // this is for safe side if we remove everything from inputField
{
if (!inputField.text [inputField.text.Length - 1].Equals (expectedString [inputField.text.Length - 1])) //if current char is not same as expected char
{
inputField.text = inputField.text.Substring (0, inputField.text.Length - 1); // this statement will remove last char
}
}
} else {
inputField.text = inputField.text.Substring (0, inputField.text.Length - 1);
}
}
}