用于停止注册表中的垃圾邮件链接的javascript代码
我们在网站上有一个会员注册表格,所有字段都通过javascript验证。最后两次注册使用地址字段和备注字段发送了恶意软件链接 Captcha不是防止这种情况发生的好方法,因此我研究了javascript中的正则表达式,以禁止这些表单字段中的“http://”,但我对如何在原始表单验证中实现代码感到困惑_ 我想知道是否有人有一段javascript代码会使在表单中写入“http://”无效,或者有一个链接指向我可以找到我们需要的javascript_ 谢谢用于停止注册表中的垃圾邮件链接的javascript代码,javascript,regex,forms,spam-prevention,Javascript,Regex,Forms,Spam Prevention,我们在网站上有一个会员注册表格,所有字段都通过javascript验证。最后两次注册使用地址字段和备注字段发送了恶意软件链接 Captcha不是防止这种情况发生的好方法,因此我研究了javascript中的正则表达式,以禁止这些表单字段中的“http://”,但我对如何在原始表单验证中实现代码感到困惑_ 我想知道是否有人有一段javascript代码会使在表单中写入“http://”无效,或者有一个链接指向我可以找到我们需要的javascript_ 谢谢 //定义全局变量: var fullN
//定义全局变量:
var fullNameReg=/^([a-zA-Z]+(-s*)[a-zA-Z]*)+$/;
var numberReg=/^([0-9]+(\s*|-)*[0-9]*)+$/;
var emailReg=/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
(0[1[1[1-9[1-1-9[1[1[1[1[1[1[1[1[1[1[1[13578]1[2[2[2[2-9[2-9[2-9[2-9[2-9[2-9[2-9[2-9[2-9[2-9[3-9-9-3-2})d \{{{{{{})2})上述上述各((((())))))第二,(,(,(,(,(0[1[1[1[1[1-1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[(29\/02\/((1[6-9][2-9]\d)(0[48][2468][048][13579][26])((16[2468][048][3579][26]))$/;
var bgcoloerr=“#FFC36E”;
var bgColor=“#FFE4BD”;
$(文档).ready(函数(){
document.getElementById(“registrationForm”).onsubmit=函数onsubmit(form)
{
//定义逻辑变量:
var formValid=true;
var focusField=null;
//定义表单元素变量:
var fName=document.getElementById(“fName”);
var dob=document.getElementById(“dob”);
var address=document.getElementById(“地址”);
var telMob=document.getElementById(“telMob”);
var telHome=document.getElementById(“telHome”);
var email=document.getElementById(“电子邮件”);
var consoleType=document.getElementById(“consoleType”);
var wishList=document.getElementById(“wishList”);
var gamerTag=document.getElementById(“gamerTag”);
var tAndC=document.getElementById(“tAndC”);
//定义表单错误范围变量:
var fNameErr=document.getElementById(“fNameErr”);
var dobErr=document.getElementById(“dobErr”);
var addressErr=document.getElementById(“addressErr”);
var telMobErr=document.getElementById(“telMobErr”);
var telHomeErr=document.getElementById(“telHomeErr”);
var emailErr=document.getElementById(“emailErr”);
var consoleTypeErr=document.getElementById(“consoleTypeErr”);
var wishlister=document.getElementById(“wishlister”);
var gamertager=document.getElementById(“gamertager”);
var tAndCErr=document.getElementById(“tAndCErr”);
//全名验证测试:
如果(fName.value==“”)
{
fNameErr.parentElement.style.backgroundColor=bgColorErr;
fNameErr.innerHTML=“您尚未输入您的姓名。
”;
formValid=false;
如果(焦点字段===null)
{
focusField=fName;
}
}
如果(!fullNameReg.test(fName.value))
{
fNameErr.parentElement.style.backgroundColor=bgColorErr;
fNameErr.innerHTML=“您输入的姓名不正确。
”;
formValid=false;
如果(焦点字段===null)
{
focusField=fName;
}
}
其他的
{
fNameErr.innerHTML=“”;
fNameErr.parentElement.style.backgroundColor=bgColor;
}
//出生验证试验日期:
如果(dob.value==“”)
{
dobErr.parentElement.style.backgroundColor=bgColorErr;
dobErr.innerHTML=“您尚未输入出生日期。
”;
formValid=false;
如果(焦点字段===null)
{
focusField=dob;
}
}
否则如果(!dobReg.测试(dob.值))
{
dobErr.parentElement.style.backgroundColor=bgColorErr;
dobErr.innerHTML=“您没有正确输入出生日期。
”;
formValid=false;
如果(焦点字段===null)
{
focusField=dob;
}
}
其他的
{
dobErr.innerHTML=“”;
dobErr.parentElement.style.backgroundColor=bgColor;
}
//地址验证测试:
如果(address.value==“”)
{
addressErr.parentElement.style.backgroundColor=bgColorErr;
addressErr.innerHTML=“您尚未输入您的地址。
”;
formValid=false;
如果(焦点字段===null)
{
焦点字段=地址;
}
}
else if(address.value.length<5)
{
addressErr.parentElement.style.backgroundColor=bgColorErr;
addressErr.innerHTML=“您没有正确输入地址。
”;
formValid=false;
如果(焦点字段===null)
{
焦点字段=地址;
}
}
其他的
{
addressErr.innerHTML=“”;
addressErr.parentElement.style.backgroundColor=bgColor;
}
//手机号码验证测试:
如果(telMob.value==“”)
{
telMobErr.parentElement.style.backgroundColor=bgColorErr;
telMobErr.innerHTML=“您尚未输入手机号码。
”;
formValid=false;
如果(焦点字段===null)
{
focusField=telMob;
}
}
else if(telMob.value.length<11 | |!numberReg.test(telMob.value))
{
telMobErr.parentElement.style.backgroundColor=bgColorErr;
telMobErr.innerHTML=“您没有正确输入手机号码。
”;
F
//Define global variables:
var fullNameReg = /^([a-zA-Z]+(-|\s*)[a-zA-Z]*)+$/;
var numberReg = /^([0-9]+(\s*|-)*[0-9]*)+$/;
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var dobReg = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;
var bgColorErr = "#FFC36E";
var bgColor = "#FFE4BD";
$(document).ready(function(){
document.getElementById("registrationForm").onsubmit = function onSubmit(form)
{
// Define logic variables:
var formValid = true;
var focusField = null;
// Define form elememt variables:
var fName = document.getElementById("fName");
var dob = document.getElementById("dob");
var address = document.getElementById("address");
var telMob = document.getElementById("telMob");
var telHome = document.getElementById("telHome");
var email = document.getElementById("email");
var consoleType = document.getElementById("consoleType");
var wishList = document.getElementById("wishList");
var gamerTag = document.getElementById("gamerTag");
var tAndC = document.getElementById("tAndC");
// Define form error span variables:
var fNameErr = document.getElementById("fNameErr");
var dobErr = document.getElementById("dobErr");
var addressErr = document.getElementById("addressErr");
var telMobErr = document.getElementById("telMobErr");
var telHomeErr = document.getElementById("telHomeErr");
var emailErr = document.getElementById("emailErr");
var consoleTypeErr = document.getElementById("consoleTypeErr");
var wishListErr = document.getElementById("wishListErr");
var gamerTagErr = document.getElementById("gamerTagErr");
var tAndCErr = document.getElementById("tAndCErr");
// Full Name validation test:
if (fName.value == "")
{
fNameErr.parentElement.style.backgroundColor = bgColorErr;
fNameErr.innerHTML = "You have not entered your name.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = fName;
}
}
else if (!fullNameReg.test(fName.value))
{
fNameErr.parentElement.style.backgroundColor = bgColorErr;
fNameErr.innerHTML = "You have not entered your name correctly.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = fName;
}
}
else
{
fNameErr.innerHTML = "";
fNameErr.parentElement.style.backgroundColor = bgColor;
}
// Date of Birth validation test:
if (dob.value == "")
{
dobErr.parentElement.style.backgroundColor = bgColorErr;
dobErr.innerHTML = "You have not entered your date of birth.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = dob;
}
}
else if (!dobReg.test(dob.value))
{
dobErr.parentElement.style.backgroundColor = bgColorErr;
dobErr.innerHTML = "You have not entered your date of birth correctly.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = dob;
}
}
else
{
dobErr.innerHTML = "";
dobErr.parentElement.style.backgroundColor = bgColor;
}
// Address validation test:
if (address.value == "")
{
addressErr.parentElement.style.backgroundColor = bgColorErr;
addressErr.innerHTML = "You have not entered your address.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = address;
}
}
else if (address.value.length < 5)
{
addressErr.parentElement.style.backgroundColor = bgColorErr;
addressErr.innerHTML = "You have not entered your address correctly.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = address;
}
}
else
{
addressErr.innerHTML = "";
addressErr.parentElement.style.backgroundColor = bgColor;
}
// Mobile Number validation test:
if (telMob.value == "")
{
telMobErr.parentElement.style.backgroundColor = bgColorErr;
telMobErr.innerHTML = "You have not entered your mobile phone number.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = telMob;
}
}
else if (telMob.value.length < 11 || !numberReg.test(telMob.value))
{
telMobErr.parentElement.style.backgroundColor = bgColorErr;
telMobErr.innerHTML = "You have not entered your mobile phone number correctly.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = telMob;
}
}
else
{
telMobErr.innerHTML = "";
telMobErr.parentElement.style.backgroundColor = bgColor;
}
// Home Number validation test:
if (telHome.value != "" && (telHome.value.length < 9 || !numberReg.test(telHome.value)))
{
telHomeErr.parentElement.style.backgroundColor = bgColorErr;
telHomeErr.innerHTML = "You have not entered your home phone number correctly.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = telHome;
}
}
else
{
telHomeErr.innerHTML = "";
telHomeErr.parentElement.style.backgroundColor = bgColor;
}
// Email Address validation test:
if (email.value == "")
{
emailErr.parentElement.style.backgroundColor = bgColorErr;
emailErr.innerHTML = "You have not entered your email address.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = email;
}
}
else if (!emailReg.test(email.value))
{
emailErr.parentElement.style.backgroundColor = bgColorErr;
emailErr.innerHTML = "You have not entered your email address correctly.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = email;
}
}
else
{
emailErr.innerHTML = "";
emailErr.parentElement.style.backgroundColor = bgColor;
}
// Game Console Type validation test:
if (consoleType.value == "")
{
consoleTypeErr.parentElement.style.backgroundColor = bgColorErr;
consoleTypeErr.innerHTML = "You have not selected your console type.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = consoleType;
}
}
else
{
consoleTypeErr.innerHTML = "";
consoleTypeErr.parentElement.style.backgroundColor = bgColor;
}
// Customer Wishlist validation test:
if (wishList.value == "")
{
wishListErr.parentElement.style.backgroundColor = bgColorErr;
wishListErr.innerHTML = "You have not entered any games in your Wishlist.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = wishList;
}
}
else if (wishList.value.length < 3)
{
wishListErr.parentElement.style.backgroundColor = bgColorErr;
wishListErr.innerHTML = "You have not entered at least one correct game in your Wishlist.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = wishList;
}
}
else
{
wishListErr.innerHTML = "";
wishListErr.parentElement.style.backgroundColor = bgColor;
}
// Customer Gamer Tag or Name validation test:
if (gamerTag.value == "")
{
gamerTagErr.parentElement.style.backgroundColor = bgColorErr;
gamerTagErr.innerHTML = "You have not entered an online ID or your name.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = gamerTag;
}
}
else
{
gamerTagErr.innerHTML = "";
gamerTagErr.parentElement.style.backgroundColor = bgColor;
}
// Terms and Conditions acceptance test:
if (!tAndC.checked)
{
tAndCErr.parentElement.style.backgroundColor = bgColorErr;
tAndCErr.innerHTML = "You have not ticket to confirm reading the terms and conditions.<br /><br />";
formValid = false;
if (focusField === null)
{
focusField = tAndC;
}
}
else
{
tAndCErr.innerHTML = "";
tAndCErr.parentElement.style.backgroundColor = bgColor;
}
// Focus on the first problem field.
if (focusField != null)
{
focusField.focus();
}
// Return the validity of the form.
return formValid;
}
});