473,804 Members | 3,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form Validation - being spammed with html links in text area

1 New Member
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 2161
b1randon
171 Recognized Expert New Member
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 Recognized Expert Top Contributor
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
johnhjohn
43 New Member
Here is a javascript validation method that I wrote:

<html>
<head>
<script language="javas cript">
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.r equired.boxa.va lue.toLowerCase ();
var box2=document.r equired.boxb.va lue.toLowerCase ();
var box3=document.r equired.textare a1.value.toLowe rCase();



// 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.innerH TML just changes the html in the span area below the form
if (box1=="" || box2=="" || box3==""){check box.innerHTML=" You must fill out all fields.";return false;}

// .indexOf() checks all of the text in a box for any matches
if (box1.indexOf(s pam1) > -1 || box1.indexOf(sp am2) > -1 || box1.indexOf(sp am3) > -1 || box1.indexOf(sp am4) > -1 ){checkbox.inne rHTML="Some or all of the information you entered is not allowed.";retur n false;}
if (box2.indexOf(s pam1) > -1 || box2.indexOf(sp am2) > -1 || box2.indexOf(sp am3) > -1 || box2.indexOf(sp am4) > -1 ){checkbox.inne rHTML="Some or all of the information you entered is not allowed.";retur n false;}
if (box3.indexOf(s pam1) > -1 || box3.indexOf(sp am2) > -1 || box3.indexOf(sp am3) > -1 || box3.indexOf(sp am4) > -1 ){checkbox.inne rHTML="Some or all of the information you entered is not allowed.";retur n false;}

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

It is required that you fill out all fields.<br />
<form name="required" action="youract ion" onSubmit="retur n 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 Recognized Expert Top Contributor
I'm not following john how does this prevent spam?
Dec 23 '06 #5
johnhjohn
43 New Member
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 Recognized Expert Specialist
Your checking will not work for a determined hacker. The following example passes your test:
[html]<script>functio n doit() {var a = 'ht' + 'tp://' + 'w' + 'ww.iis.net';wi ndow.location=a ;}</script>
<style>span {text-decoration:unde rline;color:blu e;}</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
johnhjohn
43 New Member
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 Recognized Expert Moderator MVP
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
2313
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 can use that will work for both browsers, or is there something wrong with my code? I seem to think that the problem lies with the "onclick" area of the form. This is my code, such as it is... <SCRIPT LANGUAGE="JavaScript">
9
4183
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 honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
10
1960
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 out! I invite anyone interested in whole-site validation to check out http://www.NikitaTheSpider.com/ where you can learn more about the service and have your site crawled. Thanks! Hope to see you there.
7
3624
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
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.