Filter or ignore emojis on text input

Hello.
I have a textbox and dont want the user to enter Emojis, or if they enter emojis, I want to ignore them and only get the text.

I've found this post: Helpful things you need to know where is a block to filter emojis, but I cant get it working.

Filter Emojis

To remove emojis in the text we will use :

replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, ''

I've added the Webviewer (home URL is empty) and this blocks to test it.

In the ShowAlertNotice, I see the exact text I've entered in the TextDialog, with the emojis included.

What should I do??

Thank you very much,

1 Like

Welcome to the community.

In the "filterEmojis" function, you are appending text without double quotes. and without a . dot. Add a dot before "replace(" and the text should have double quotes covered at begging and the end.

2 Likes

Hello!
Thanks for your fast answer,

I've noted what you said and added the dot and the quotes but still see the same text with emojis in the Notice :thinking:

The text in the third Join box is ".replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, ''

as copied from the original post.

1 Like

Now it looks correct.
And you're showing the same text variable in the toast message and that will be never changed.
Drag an event yellow block called "WebViewStringChange" and show the value in the toast.

1 Like

@Luciano_M Welcome to our community !
It should look like this -
solution

1 Like

Hello, thanks for the answers.
I still cant get it working :thinking:

I have the blocks like this just to try.
I right click DO IT in show the text dialog to show it.
Im using AI companion
The home URL in the web viewer its empty

the js code its like this:
I dont know JS but I've added a ')' before .replace

window.AppInventor.setWebViewString("response").replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, '');

I see the alert, but the result text is exactly the same as input

Do I need some .txt file with javascript code??

Thank you

@Luciano_M There's a small mistake, you have to put the double quotation mark inside the bracket.

Your mistake - window.AppInventor.setWebViewString("response)".replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, '');

Correction - window.AppInventor.setWebViewString("response").replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g'');

@Luciano_M I've got a very effective solution for you.


  1. Download my script :
    SalDevScript.txt (1.2 KB)
    and don't forget to change the extension to .html

  2. Upload my code to your project at MIT AI2

  3. Make logic blocks like this :
    blocks

Aia Project :
NewExample1.aia (2.7 KB)