• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.5 Disallow phone numbers in thread title


Noticed that in my community, few spammers are starting thread giving their phone number in the thread title like - "99147 *****" . Is there a spam management setting in Xenforo where I could disallow a specific sequence of numbers in the thread title.



Well-known member
For phrases, you would have to know the number before they added it, unless you did it with regex, knowing the format of common numbers

I customised StopHumanSpam for myself on one forum to do exactly this, in theory the solution could be applied to spam phrases (I believe it allows regex)
- the code is still in there, I would only need to comment it back in

The sort of numbers I tried to match were mobiles, or long strings of numbers such as these

// 07875007195 should match
// 07875 007195 should match
// 07875 - 007195 should match
// 07875m007195 should not match
// x07875007y should not match

In code, this is the solution I used (don't know how useful it is too you, I could turn this functionality on in StopHumanSpam if needed)

        // years are going to cause an issue, for instance 1977 - 2013
        // so first remove exact matches for <not num>[1-9][0-9][0-9][0-9]<not num> (basically, 4 numbers in a row with a space
        $message = preg_replace('/[^0-9][1-9][0-9][0-9][0-9][^0-9]/i', '', $message);
        // this does allows users to sneak phone numbers in like: 1787 5107 195 (but the phone numbers can not start with 0... which almost all of them do, so thats fine
        preg_match('/(?<=[^a-z$£\pL])[0-9]([^a-z$£\pL]*?)[0-9]([^a-z$£\pL]*?)[0-9]([^a-z$£\pL]*?)[0-9]([^a-z$£\pL]*?)[0-9]([^a-z$£\pL]*?)[0-9]([^a-z$£\pL])/i', $message, $matches);
There will always be ways around it (e.g. 0787 5007 195 ), but it's worked pretty well now for years

There's probably a simple regex pattern to match, but it won't necessarily catch the above without catching things like years, so a basic 1 line of regex might not be great

My regex is dire, there are many people with good regex experience @Mike being one of them, maybe he can provide a solution
Last edited: