Our website has a membership registration form with JavaScript validation. Unfortunately, the last two registrations have included malware links in the address and notes fields. Using Captcha is not an effective solution to prevent this issue. I've been exploring regular expressions in JavaScript to ban entries containing 'http://' in these form fields, but I'm having trouble implementing the code into the existing form validation logic.
If anyone has a snippet of JavaScript code that can detect and invalidate 'http://' entries in our form, or if you know where I can find such code, please share it. Thank you.
//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;
...
// The rest of the original code remains unchanged for brevity.