更好的垃​​圾邮件过滤器代码结构

时间:2013-11-27 11:01:42

标签: javascript jquery

我为客户编写了垃圾邮件过滤器,拒绝在特定字段(输入)中提交包含http的表单。

我现在正在尝试将其改编为一个网站,该网站有多种形式,但每个输入的ID也不同,这是其他功能所需的。

如何重新编写此代码,以便它适用于表单中的任何输入而不管字段ID?

Html

<form action="#" name="form">
<input type="text" name="txt" id="txt" onblur="validate('txt');"/>
<p id="alert1" style="display:none;"> Please remove the link from this field to   continue with the form submission. </p>
<input type="text" name="txt1" id="joso"/>
<input type="submit" id="submit"/>
<p id="alert2" style="display:none;"> Please remove the link from this comments area to continue with the form submission </p>
</form>

的Javascript

function validate(id) {
    var txtbox = document.getElementById('txt');
    var txtvalue = txtbox.value;
    txtindex = txtvalue.indexOf('http');
    if (txtindex!=-1) {
        document.getElementById('alert1').style.display = 'block';
        document.getElementById("submit").disabled = true;
    } else {
        document.getElementById("submit").disabled = false;
        document.getElementById('alert1').style.display = 'none';
    }   
}

解决方案效果

对于那些对解决方案感兴趣的人 - 它运行得很好,这就是为什么我想把它移植到我所有其他网站上。它减少了我们获得的90%的垃圾邮件,即使我们安装了另一个capcha解决方案,它增加了no。由于我们的CMS提供的capcha解决方案太难以阅读,因此我们失去的有效要求。它的性能也优于我们之前使用的capcha。

0 个答案:

没有答案