Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Sep 02, 2015 at 10:42 AM by hgaur725 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by hgaur725 · Aug 31, 2015 at 05:48 PM · inputfield

How to validate the characters of the strings to the characters typing via mobile keyboard?

Hey guys i am working on the prototype like this:link text

how can i validate the characters like in this game. right now i am doing this

nameInputField.onValidateInput += delegate(string input, int charIndex, char addedChar) { return MyValidate (addedChar); };

 private char MyValidate(char charToValidate)
 {

             //Checks if a dollar sign is entered....
         if (charToValidate == textChar[i])
             {
                 // ... 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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1

Answer by amanpu · Sep 02, 2015 at 06:42 AM

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);
         }
 
     }
 }









Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hgaur725 · Sep 02, 2015 at 01:17 PM 0
Share

Thanks @amanpu it worked perfectly. thats what i wanted thanks a lot . and please make it as answer :)

avatar image amanpu · Sep 02, 2015 at 01:32 PM 0
Share

@hgaur if you like it then upvote it and accept as answer this will help other users to find correct answer thanks

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

UI 4.6 input field how do I use the .onendedit? 1 Answer

InputField.ActivateInputField() giving NullReferenceException error 1 Answer

Is there a notepad-like (preferably a notepad++-like) in-game text editor for use in Unity5? 0 Answers

Catching get focused for UI InputField 0 Answers

Making an image appear from a different script 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges