c# - How to restrict Emoji range u2600-u26FF for a text box -
i restrict emojis in text box of range u2600-u26ff using regex.
i tried this, fails.
private static readonly regex regexemoji = new regex(@"[\u1f600-\u1f6ff]|[\u2600-\u26ff]");
i restric user adding emojis in wp8
thanks in advance.
because .net doesn't support surrogated pairs in regexes. have decompose them manually. make clear, char
in .net 16 bits, 1f600
needs 2 char
. solution decompose them "manually".
private static readonly regex regexemoji = new regex(@"\ud83d[\ude00-\udeff]|[\u2600-\u26ff]");
i hope have decomposed them correctly.
i used site: http://www.trigeminal.com/16to32andback.asp
to decompose low , high range \u1f600 == \ud83d \ude00
, \u1f6ff == \ud83d \udeff
. first part of surrogate pair "fixed": \ud83d
, other range.
example code (http://ideone.com/0o6qbt)
string str = "hello world 😀🙏☀⛿"; // 🌀 1f600 grinning face, 1f64f person folded hands, 2600 black sun rays, 26ff white flag horizontal middle black stripe regex regexemoji = new regex(@"\ud83d[\ude00-\udeff]|[\u2600-\u26ff]"); matchcollection matches = regexemoji.matches(str); int count = matches.count; console.writeline(count);
if want range 1f300-1f6ff
... it's d83c df00
d83c dfff
, d83d udc00
d83d deff
string str = "hello world 🌀😀🙏☀⛿"; // 1f300 cyclone, 1f600 grinning face, 1f64f person folded hands, 2600 black sun rays, 26ff white flag horizontal middle black stripe regex regexemoji = new regex(@"\ud83c[\udf00-\udfff]|\ud83d[\udc00-\udeff]|[\u2600-\u26ff]");
Comments
Post a Comment