SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2003
    Location
    England
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Deny certain words

    Hi,

    Just wondering if you could help me with a small problem, and that is i run a classified ads site, however i would like to deny certain words in there description, such as .com, www, .de and some of those words, and display a alert box before submitting the form.

    Could someone help me locate a script that could do that or could provide the code.

    Thank you
    Kirk

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a note... javascript protection will only help you if the user has javascript enabled. You can get stronger protection from server-side prevention.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    While maintaining samsm's comments in mind:

    1) create an array containing the words you wish to check against.
    2) parse the ad, using the split(" ") method, which will create an array of words
    3) loop through the 2nd array comparing it against the 1st array

    something like this:

    var myList = new Array();
    myList[0] = 'com';
    ....
    myList[n] = 'de';

    function checkIt(fieldObj)
    {
    tmp = fieldObj.value.split(" ");
    for (var i = 0; i < myList.length; i++)
    for (var j = 0; j < tmp.length; j++)
    if (myList[i] == tmp[j])
    alert("blahblahblah")
    }

    Note: you will have to deal with punctuation, etc.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Vincent Puglia
    Hi,

    While maintaining samsm's comments in mind:

    1) create an array containing the words you wish to check against.
    2) parse the ad, using the split(" ") method, which will create an array of words
    3) loop through the 2nd array comparing it against the 1st array

    something like this:

    var myList = new Array();
    myList[0] = 'com';
    ....
    myList[n] = 'de';

    function checkIt(fieldObj)
    {
    tmp = fieldObj.value.split(" ");
    for (var i = 0; i < myList.length; i++)
    for (var j = 0; j < tmp.length; j++)
    if (myList[i] == tmp[j])
    alert("blahblahblah")
    }

    Note: you will have to deal with punctuation, etc.

    Vinny
    Actually, I suggest using regular expressions in this case. They're far more powerful and won't catch a "false positive" for the most part. More information on regular expressions can be had at http://www.regexlib.com/. You can also use the same expressions on both the client and the server-side for extra-tight validation in the event that scripting is disabled.

    Off Topic:

    Another Vincent! WooHoo!

  5. #5
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    Just a note... javascript protection will only help you if the user has javascript enabled. You can get stronger protection from server-side prevention.
    you could create the form using javascript for a bit more security
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While that would prevent non-javascript users seeing the form and therefore not being able to use it, the point Samsm was making was that you are cutting out an audience if you make it in Javascript. Therefore you are COMPLETLY cutting out that audience, instead of just not protecting that.

    Kind of a catch-22.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •