Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to validate the characters of the strings to the characters typing via mobile keyboard?

    • 1
    • 0
    • 0
    • 3
    • 0
    • 0
    • 0
    • 414
    Answer it

    Hey guys i am working on the prototype like this: https://www.youtube.com/watch?v=aGwqi5wK5ZA

    how can i validate the characters like in this game.

    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! i am using unity 5 and its ui inputfield.

 3 Answer(s)

  • Hey, Yes I have gone through the video.

    I am saying something like this:-

            string ToPrint = "Hello";
            string temp = "";
            InputField myTxt;
            string toCheck = "";
    
    
            void Start()
            {
                toCheck = ToPrint.Substring (0, 1);
            }
    
            void Update () 
            {
                temp = Input.inputString;
    
                if (temp == toCheck)
                                ShowText (temp);
            }
    
            void ShowText(string val)
            {
                myTxt.text += val;
    
                if(myTxt.text.Length < ToPrint.Length)
                toCheck = ToPrint.Substring (myTxt.text.Length, 1);
            }
    

    Hope this will work for you.

  • Hey, You don't have to put the validation direct on your final InputField.

    My suggestion is, that you use a temporary variable for the validation and if your validation comes successful(true) then you can put the correct string in the final InputField.

    So with this if user will press wrong keys that will not display in your InputField.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: