Is there a way to test if a character is an emoji?

I have a text box and only want the user to be able to type in emoji. Is there a test to check if a character is an emoji?

Yes, you can check if a character or a full string (text) if contains an emoji.

Just execute this JavaScript in the invisible web-view:

window.AppInventor.setWebViewString(/\p{Extended_Pictographic}/u.test('TEXT'));

And then use a block called "WebViewStringChangeEvent".

You should have to check conditions like this:

Source

And if you want to remove emojis refer to this topic:

and navigate to the section called "Filter emojis".

EmojiCheck.aia (1.9 KB)

2 Likes

Thank you! I'll be attempting this tomorrow, and will let you know how it goes.
Also, I don't want to remove emoji; I want to remove everything EXCEPT emoji. I think this solution should work well, though!

1 Like

Hello! Sorry to bother you again.
Your code to remove emojis works brilliantly, but I need to do the opposite: remove everything except emoji. I tried searching on the internet for how to do that, or for how to negate a regex (I think you used a regex?) but what I tested did not work. I'm not familiar with JavaScript or regexes at the moment.
How should I change the replace command to remove everything except for emoji?
Thanks!

1 Like

First split the text into a character array then you loop over each character and if it's an emoji then you append it into a new text variable if it's not emoji, then don't append it. Simple.

Lemme know if you're stuck somewhere :slightly_smiling_face:

1 Like

I'll research how to split the text, and will try this later! Thanks :slight_smile:
If I get stuck I'll send a reply.

1 Like

I think I got it!
I cant split the text into a character array, because some characters which are a single grapheme contain multiple Unicode characters.
But even if I can't, the grapheme-splitter library can!
I added the library into my project, and can use it to get a proper character array, then use the process you described.
If I have any problems I'll ask them, but I think I got it now. As a newer App Inventor user, thank you for showing me all these tools!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.