博客簿

只修改模板用纯js实现Emlog评论验证防止垃圾评论教程

时间:4年前   阅读:1960

使用 emlog 博客程序的朋友,大部分可能经常遇到一些垃圾评论, 以前有写过一篇《 给EMLOG评论框加上√防止垃圾评论》,今天讲的教程可以和上面的同时使用的。以下教程以默认模板为例

第一步、在全局js中加入如下代码:里面的一些正则可以自行替换成你想要的

function SLyz(){
if(document.commentform.comname.value.length == 0){alert("请输入昵称");document.commentform.comname.focus();return false;}
var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;if(!reg.test(document.commentform.commail.value)){alert("1、邮箱地址是否填写 \r\n2 、邮箱地址是否正确");document.commentform.commail.focus();return false;}
var reg = /^(http:\/\/|https:\/\/)([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/;if(!reg.test(document.commentform.comurl.value) && (document.commentform.comurl.value)){alert("网址格式必须加http://或https://且网址结尾不能有“/”;次选为选填项,可不填写");document.commentform.comurl.focus();return false;}
if(document.commentform.comment.value.length == 0){alert("请填写评论内容且评论内容需包含中文");document.commentform.comment.focus();return false;}
}

第二步、在模板文件module.php中找到代码

<form method="post" name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform">

修改为下面代码

<form method="post" name="commentform" action="<?php echo BLOG_URL; ?>index.php?action=addcom" id="commentform" onSubmit="return SLyz();">

以上2步就完成了

上一篇:解决Emlog文章详情页伪静态后URL不是唯一地址的教程

下一篇:Emlog评论通过QQ获取昵称资料

网友评论