Form Validation - being spammed with html links in text area

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leslietulip
    New Member
    • Dec 2006
    • 1

    #1

    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
  • b1randon
    Recognized Expert New Member
    • Dec 2006
    • 171

    #2
    Originally posted by leslietulip
    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:
    Code:
    if (commentText.matches(/.*http://.*) != null)
         blockPost();
    else
         post();

    Comment

    • AricC
      Recognized Expert Top Contributor
      • Oct 2006
      • 1885

      #3
      You could try to use CAPTCHA I've never used it but it may help to at least slow the spammers.

      Comment

      • johnhjohn
        New Member
        • Dec 2006
        • 43

        #4
        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>

        Comment

        • AricC
          Recognized Expert Top Contributor
          • Oct 2006
          • 1885

          #5
          I'm not following john how does this prevent spam?

          Comment

          • johnhjohn
            New Member
            • Dec 2006
            • 43

            #6
            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.

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              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:

              Comment

              • johnhjohn
                New Member
                • Dec 2006
                • 43

                #8
                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).

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Originally posted by leslietulip
                  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.
                  U229 skriver om det å låne penger. Her viser vi deg hvordan du kan få de beste betingelser med lav rente.

                  or
                  Click here for another ingenious method

                  Comment

                  Working...