Open febg11 opened 4 years ago
If i get the string after typing them in the code unit field has [65039, 65039, 65039, 65039, 65039, 65039] as a value. This seems to be this https://unicode-table.com/en/FE0F/
Could you try and use this regex it seems to fix the problem https://github.com/mathiasbynens/emoji-regex/blob/master/index.js
@febg11 it's kinda different, the regex by EmojiParser
is to parse emoji, not to filter. If you want to filter emoji runes from TextField
or similar widgets, you need to filter the \ufe0f
character.
Use this
TextField(
onChanged: (text) {
print("Word count: " + text.length.toString());
},
inputFormatters: [
BlacklistingTextInputFormatter(RegExp(
r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|\ufe0f)'
))
],
)
Hi @petehouston
Sorry for not replying for a long time I only just got around to doing this. I have tested your regex which fixes a lot of my problems however it does not detect the English, Welsh and Scottish flags as well as the unofficial flags which can be seen on here.
This is part of my test that fails.
String regexNew = r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|\ufe0f)';
RegExp regex = RegExp(regexNew);
print("Starting british flags");
String flags2 = "🏴🏴🏴";
String flags2Output = flags2.replaceAll(regex, "");
expect(flags2Output, "");
print("Starting Unofficial Flags Emojis");
String unofficialFlagsEmojis = "🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴";
String unofficialFlagsEmojisOutput = unofficialFlagsEmojis.replaceAll(regex, "");
expect(unofficialFlagsEmojisOutput, "");
I am not sure what the unofficial flags even are.
Could you help me adjust the regex to ensure that the British flags and possibly the unofficial flags are black listed in the regex.
Thank you so much for all you have done.
Interesting. I will take a look on those emojis.
Thanks Pete I really appreciate your help 😊
Hi Pete did you manage to take a look at this?
I was wondering if you could help me with blocking emojis from being typed into input boxes.
The emoji 🌬️ (and a few others) still get typed into input boxes that have been blacklisted with your regex.
They dont get typed but they get counted as input. E.g. if you have a hint in the text box (or character count) and type the emoji the hint will disappear and the character count will increase to 1. There is actually no input in the box, just empty space.