Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[SOLVED] Disable Emoji in mobile keyboard

Discussion in 'Scripting' started by malak, Sep 7, 2018.

  1. malak

    malak

    Joined:
    Jan 23, 2014
    Posts:
    65
    Hi everybody ,

    Today i'm getting stuck with emoji on mobile keyboard :(

    i've start to create an apk who you can send encrypted text message to your friends from database but i get error if my friend send me a text with emoji :(

    the encryption fail and i get error .

    Do you know how can i disable emoji from mobile keyboard ?
    or if you know another way to get it work ?
    like filter the UI text ?
    any help are welcome .

    thanks by advance for your time .
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
  3. malak

    malak

    Joined:
    Jan 23, 2014
    Posts:
    65
    thanks for the reply but i dont really understand in your link the code :(

    i think i can find something with characters filter or content type in inputfield .

    if i put content type Name in input field i get special character blocked (like i want) but all words get first letters with capitalisation :(

    and if i choose content type password all is good except the text is hidden by stars :(

    please help me to find a way .
     
    Last edited: Sep 9, 2018
  4. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,315
    You're still looking at the keyboard side. I'm talking about the input validation side. Check the characters that are being input by the user. If it looks like an emoji, remove it.
     
  5. malak

    malak

    Joined:
    Jan 23, 2014
    Posts:
    65
    i find another way ,:

    i set the content type as password ,
    duplicate the Text value from the inputfield and set it to a new Text.UI

    so now when i write on the mobile keyboard emoji's gone and i can see what i write because stars are removed
    ;)
     
  6. ranch000

    ranch000

    Joined:
    Mar 24, 2017
    Posts:
    18
    Hi, in this case, the stars will be removed from the in-game input field but mobile keyboard input box will still show stars isn't it?
     
  7. imran4125

    imran4125

    Joined:
    Jul 12, 2017
    Posts:
    17
    any solution ?
     
  8. MaggerFabio

    MaggerFabio

    Joined:
    Oct 17, 2017
    Posts:
    11
    Came through this today while trying to find a way to disable Emojis on an InputField. Came up with the solution below, which seems to work well so far.

    Code (CSharp):
    1.  
    2. // Add the onValidateInput delegate to your Input Field (This assumes you are not using any Character Validation in your Input Field already)
    3. private char OnValidateInput(string text, int charIndex, char addedChar)
    4. {
    5.             // Filter out the Unicode categories you want (example below), keep in mind that, while this can filter out Emojis, it can also filter out chars you might want to keep (e.g. Asiatic languages, which I don't need to care about right now), so this is not a perfect solution.
    6.             var unicodeCategory = char.GetUnicodeCategory(addedChar);
    7.  
    8.             switch (unicodeCategory)
    9.             {
    10.                 case UnicodeCategory.OtherSymbol:
    11.                 case UnicodeCategory.Surrogate:
    12.                 case UnicodeCategory.ModifierSymbol:
    13.                 case UnicodeCategory.NonSpacingMark:
    14.                     // Refer to https://www.compart.com/en/unicode/ for a comprehensive list of Unicode categories and chars
    15.                     return char.MinValue;
    16.                 default:
    17.                     return addedChar;
    18.             }
    19. }
    20.  
     
    masoudarvishian likes this.
  9. masoudarvishian

    masoudarvishian

    Joined:
    Jan 15, 2015
    Posts:
    9
    Thank you, solved my problem.