The method of JS judging and filtering emoji expression

Source: Internet
Author: User

First, JS to determine whether the text has emoji expression
Isemojicharacter (substring) {for (var i = 0; I <substring.length; i + +) {var hs = Substring.charcode          at (i); if (0xd800 <= HS && HS <= 0XDBFF) {if (substring.length> 1) {var ls = su                  Bstring.charcodeat (i + 1);                  var UC = ((hs-0xd800) * 0x400) + (LS-0XDC00) + 0x10000;                   if (0x1d000 <= UC && UC <= 0x1f77f) {returns true;              }}} otherwise if (substring.length> 1) {var ls = substring.charcodeat (i + 1);               if (ls = = 0x20e3) {returns true;               }} else {if (0x2100 <= HS && HS <= 0X27FF) {returns true;               } else if (0x2b05 <= HS && HS <= 0x2b07) {returns true;               } else if (0x2934 <= HS && HS <= 0x2935) {returns true; } else if (0x3297 <= HS && HS <= 0x3299) {returns true; } else if (hs = = 0XA9 | | HS = = 0xae | | HS = = 0x303d | | HS = = 0x3030 | | HS = = 0x2b55 | | HS = = 0x2b1c | | HS = = 0x2b1b | |               HS = = 0X2B50) {returns true;  }          }      }  }
Second, JS file filter emoji Emoticons
    使用JS过滤表情符号表情的主要原因:输入标签中输入表情符号表情,表单提交后插入数据库。报错原因:        因为UTF-8编码有可能是两个,三个,四个字节.Emoji表情是4个字节,而MySQL的utf8编码最多3个字节,所以数据插不进去。        于是找到两个解决方案:          1.将Mysql的编码从utf8转换成utf8mb4          2.前端JS校验过滤掉emoji表情

The method of JS judging and filtering emoji expression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.