Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
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
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
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