Could someone lead me on finding a regular expression that blocks a comma separated list of Spam words I already have?
The regular expression needs to match a string with the spam word list I already have.
Not that it matters, but I am using PHP.
Could someone lead me on finding a regular expression that blocks a comma separated list of Spam words I already have?
The regular expression needs to match a string with the spam word list I already have.
Not that it matters, but I am using PHP.
You could generate a regular expression that matches anything containing a spamword from you list by replacing you commas with |
and adding round brackets and word boundaries.
If your spamlist is "spam1,spam2,spam3"
, your regular expression would be "\b(spam1|spam2|spam3)\b"
.
You can use JavaScript to prevent the user from submitting spam data. Such as:
var spam_words = ["word1", "word2", "word3"];
var regex = new RegExp(spam_words.join("|"));
if(regex.test(form_data_you_wanna_test)){
// stop submit
}else{
// submit
}
Try this:
\b(word1|word2|...)\b
The \b
will match between a word character and a non-word character (so that the expression won't match if the words appear as part of a longer word).