473,382 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Form Validation - being spammed with html links in text area

Greetings - this is the first time I am posting to this forum. I am using Javascript to ensure that the user enters all required fields in a form. However, this form is being spammed to death with the user or a robot filling up all fields and sending tons of html links in the text area of a comments/question box. I want to use javascript to see if there are any links in the fields and if so, not allow the form to be submitted.

Does anyone have a script that searches for html links or a script that searches for a specific string that I could modify to search for "http://"? Thanks for any help you can offer.
Leslie
Dec 22 '06 #1
8 2143
b1randon
171 Expert 100+
Greetings - this is the first time I am posting to this forum. I am using Javascript to ensure that the user enters all required fields in a form. However, this form is being spammed to death with the user or a robot filling up all fields and sending tons of html links in the text area of a comments/question box. I want to use javascript to see if there are any links in the fields and if so, not allow the form to be submitted.

Does anyone have a script that searches for html links or a script that searches for a specific string that I could modify to search for "http://"? Thanks for any help you can offer.
Leslie
Leslie, this should do ya:
Expand|Select|Wrap|Line Numbers
  1. if (commentText.matches(/.*http://.*) != null)
  2.      blockPost();
  3. else
  4.      post();
  5.  
Dec 22 '06 #2
AricC
1,892 Expert 1GB
You could try to use CAPTCHA I've never used it but it may help to at least slow the spammers.
Dec 22 '06 #3
Here is a javascript validation method that I wrote:

<html>
<head>
<script language="javascript">
function checkfields(){

/* Getting values of the three boxes and
making it all lower case so it cannot
get past the checking system */

var box1=document.required.boxa.value.toLowerCase();
var box2=document.required.boxb.value.toLowerCase();
var box3=document.required.textarea1.value.toLowerCase ();



// Spam that a user might enter
var spam1="href=";
var spam2="http://";
var spam3=".com";
var spam4="www.";



/* Determining if the boxes are empty
or if they contain spam */

// The checkbox.innerHTML just changes the html in the span area below the form
if (box1=="" || box2=="" || box3==""){checkbox.innerHTML="You must fill out all fields.";return false;}

// .indexOf() checks all of the text in a box for any matches
if (box1.indexOf(spam1) > -1 || box1.indexOf(spam2) > -1 || box1.indexOf(spam3) > -1 || box1.indexOf(spam4) > -1 ){checkbox.innerHTML="Some or all of the information you entered is not allowed.";return false;}
if (box2.indexOf(spam1) > -1 || box2.indexOf(spam2) > -1 || box2.indexOf(spam3) > -1 || box2.indexOf(spam4) > -1 ){checkbox.innerHTML="Some or all of the information you entered is not allowed.";return false;}
if (box3.indexOf(spam1) > -1 || box3.indexOf(spam2) > -1 || box3.indexOf(spam3) > -1 || box3.indexOf(spam4) > -1 ){checkbox.innerHTML="Some or all of the information you entered is not allowed.";return false;}

}
</script>
</head>
<body>

It is required that you fill out all fields.<br />
<form name="required" action="youraction" onSubmit="return checkfields();">

Box 1: <input type="text" name="boxa" value=""><br />
Box 2: <input type="text" name="boxb" value=""><br />
Box 3: <textarea name="textarea1"></textarea><br />
<input type="submit" name="submit" value="Check Fields"><br />
</form>
<span id="checkbox"></span>
</body>
</html>
Dec 23 '06 #4
AricC
1,892 Expert 1GB
I'm not following john how does this prevent spam?
Dec 23 '06 #5
This script will not submit the form if it contains the items expressed in the function. If any of the values in the form matches the variables spam1, spam2, spam3, or spam4, the form will not be submitted.
Dec 25 '06 #6
ronverdonk
4,258 Expert 4TB
Your checking will not work for a determined hacker. The following example passes your test:
[html]<script>function doit() {var a = 'ht' + 'tp://' + 'w' + 'ww.iis.net';window.location=a;}</script>
<style>span {text-decoration:underline;color:blue;}</style>
<span onclick='doit()'>Hit me</span>[/html]

You will have to use a more structured approach to intercepting, like stripping or replacing all tags first, before looking at the content.

Ronald :cool:
Dec 25 '06 #7
Yeah, mine does need to be modified. I wrote it so it could be modified easliy (so she could change the values of the spam variables more easily).
Dec 27 '06 #8
acoder
16,027 Expert Mod 8TB
Greetings - this is the first time I am posting to this forum. I am using Javascript to ensure that the user enters all required fields in a form. However, this form is being spammed to death with the user or a robot filling up all fields and sending tons of html links in the text area of a comments/question box. I want to use javascript to see if there are any links in the fields and if so, not allow the form to be submitted.

Does anyone have a script that searches for html links or a script that searches for a specific string that I could modify to search for "http://"? Thanks for any help you can offer.
Leslie
You can use CAPTCHA as mentioned earlier, e.g.
http://www.u229.no/stuff/Captcha/
or
Click here for another ingenious method
Dec 27 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
10
by: NikitaTheSpider | last post by:
Hi all, I would like to announce the alpha release of a service that does bulk/batch HTML validation, link checking and more. During alpha testing, the service is free -- I need people to try this...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.