JavaScript-there is no perfect code for filtering QQ numbers (JS or PHP)

Source: Internet
Author: User
1. Filter normal QQ number (qq:8141334)
2. Ignore the number string that appears in the URL: http://bangpai.taobao.com/group/thread/16151013-290178703.htm

滤特殊QQ号 ( ⑧①④①③③④ 、八一四一三三四)it would be better if we could do it.

Reply content:

1. Filter normal QQ number (qq:8141334)
2. Ignore the number string that appears in the URL: http://bangpai.taobao.com/group/thread/16151013-290178703.htm

滤特殊QQ号 ( ⑧①④①③③④ 、八一四一三三四)it would be better if we could do it.

Ideas:

    1. Use regular replacement to remove all URLs from the original text
    2. And then look for more than 5 consecutive digits just fine.

As for the filter special QQ number, I think is in vain. The magic of Unicode is often underestimated by many people:

    • An ordinary number, such as 9, can be written in 9九玖⑨⑼⒐٩⁹₉⓽❾➈➒㈨㊈ so many ways.
    • Not to mention 1, 0, etc. can also be confused with the letters I, O, L and derivative ⒾⓞⓛⓄ⒧⒪ variants
    • mixed with complex control characters. Can you find AB a 0-width space in the middle of these two letters?

When the surrender or die surrendered, he surrendered. When the QQ number is sufficient, don't try to deal with the special symbols.

Note: Even if it is necessary to deal with spam, it is much more effective to filter Chinese words than to counter the special sign QQ.

can be filtered, but not all of them are filtered out.
Filter principle, the inside of the 1234, ①② all replaced by a number, and then match whether it is.

Ideas

  class filterqq{public static function hasqq ($string = ') {$stri        ng = Self::replace ($string); Return Preg_match ('/[1-9]{1}[0-9]{5,12}/', $string)?    True:false;            The public static function replace ($string = ') {$arr = array (' 0 ' = = Array (' 0 ', ' 0 ', ' 0 '), ' 1 ' = Array (' 1 ', ' One ', ' ① '), ' 2 ' = = Array (' 2 ', ' two ', ' ② '), ' 3 ' = ' Array (' 3 ', ' Three ', ' ③ '), ' 4 ' = = Array (' 4 ', ' Four ', ' ④ '), ' 5 ' = = Array (' 5 ', ' Five ', ' ⑤ '), ' 6 ' = = Array (' 6 ', ' Six ', ' Liu '), ' 7 ' = = Array (' 7 ', ' Seven ', ' ⑦ '), ' 8 ' = = Array (' 8 ', ' Eight ', ' ⑧ '), ' 9 ' = AR Ray (' 9 ', ' Long ', ' nine '), ' = ' + array_unique (explode (' | ', ', |. |;| ' | ' | +|-|-| | |, |~|@|#|¥|%|        ...')), );    Return Str_replace (Array_values ($arr), Array_keys ($arr), $string); }}//Use method $string = ' Ashton sent the occurrence of the occurrence of the put Ah Ah '; Var_dump (FILTERQQ::HASQQ ($string));  

Using regular expressions

  • 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.