Skip to main content
witoldw0001
October 17, 2022
Solved

Ban emojis in comments

  • October 17, 2022
  • 5 replies
  • 0 views

Hello!

I would like to prevent users from using emojis in comments, however I have absolutely no idea how to accomplish that. Have you got any advice, folks?

Best answer by mikes0011

I'd suspect simply passing hand-entered text through clean() would filter out most or all such things.  And if not, you could always go brute-force and use cleanWith() to enforce a strict whitelist of allowed characters (though you'd have to be fairly careful to be inclusive enough of unusual-but-allowable special characters).

5 replies

stefanhelzle0001
Brainy
October 17, 2022

Why do you want to ban them? Because of database issues?

witoldw0001
October 17, 2022

It has been requested, I am not sure why, but I doubt there were any database considerations behind this request.

stefanhelzle0001
Brainy
October 17, 2022

Blocking a set of specific characters is not simple. To specifically block emojis, you would have to exclude multiple ranges of unicode characters.

Something like this: https://gist.github.com/aabed/63c4bfde6a510395657a2ee3383716dd

mikes0011
mikes0011Answer
Brainy
October 17, 2022

I'd suspect simply passing hand-entered text through clean() would filter out most or all such things.  And if not, you could always go brute-force and use cleanWith() to enforce a strict whitelist of allowed characters (though you'd have to be fairly careful to be inclusive enough of unusual-but-allowable special characters).

The Expression Guru
witoldw0001
October 31, 2022

Thank you. That would probably the best way.