Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-06-03 12:57:11

arkham
Member
Registered: 2005-03-27
Posts: 102
Website

how can i stop comment spam with a regular expression test?

I’m using a few anti-spam TXP plugins on my site and they’ve helped somewhat but there’s been this on-going thing where a few times a day I receive spam comments from unique ip’s, unique url’s, unique keywords in the name field..

The only thing all this spam has in common is the entire comment they leave will always be a 6 character string made up of numbers and letters.

I’d like to do a regular expression check and if the comment someone leaves is only 6 characters long and includes at least one number then I’d like to have the comment be moderated or marked as spam or just not allowed.

Can anyone tell me how to go about doing this?

Thanks in advance.

Offline

#2 2007-06-03 13:56:37

FireFusion
Member
Registered: 2005-05-10
Posts: 698

Re: how can i stop comment spam with a regular expression test?

You could try a Javascript solution using JQuery

Offline

#3 2007-06-03 14:06:39

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: how can i stop comment spam with a regular expression test?

If you’re only looking for the regex to do this, assuming the comment is in $comment:

if (preg_match('/^\s*[a-z0-9]{6}\s*$/i', $comment) and preg_match('/\d/', $comment)) {
  mark as spam
}

It first checks for a comment that only contains a string of 6 alphanumeric characters, then also checks if at least one of them is a number.

Last edited by ruud (2007-06-03 14:17:21)

Offline

#4 2007-06-03 23:59:31

arkham
Member
Registered: 2005-03-27
Posts: 102
Website

Re: how can i stop comment spam with a regular expression test?

ruud wrote:

if (preg_match('/^\s*[a-z0-9]{6}\s*$/i', $comment) and preg_match('/\d/', $comment)) {
  mark as spam
}

Where would I add that?

Offline

#5 2007-06-04 00:02:59

arkham
Member
Registered: 2005-03-27
Posts: 102
Website

Re: how can i stop comment spam with a regular expression test?

FireFusion wrote:

You could try a Javascript solution using JQuery

Looks interesting. I may give that a try.

Offline

#6 2007-06-04 05:32:32

arkham
Member
Registered: 2005-03-27
Posts: 102
Website

Re: how can i stop comment spam with a regular expression test?

arkham wrote:

Where would I add that?

Never mind that question. I added it to an anti-spam plugins. Works like a charm.

Thanks!

Offline

Board footer

Powered by FluxBB