dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: bad word blocker

  1. #1
    Join Date
    Jun 2017
    Posts
    8

    bad word blocker

    Hi,
    I'm trying to validate a text field using a bad word filter script I found on the net. What's happening now is if I post "badword1" the alert will come up, if I use "badword1 is ok" it posts. is there a way to fix this so it sees the badword and shows the alert?

    script I'm using that works if only one word is used.....

    var bad = new Array('badword1','badword2','badword3');
    var count=0;
    var fields=document.getElementsByTagName('INPUT');
    for (var i=0;i<fields.length;i++) {
    if ((fields[i].type=='text')&&(fields[i].value!=''))
    for (var j=0; j<bad.length;j++) {
    if (fields[i].value.toLowerCase()==bad[j].toLowerCase()) {
    alert('Sorry '+bad[j]+' is trademarked \n we only do custom and unique designs\n\n Please read the description for further information.');
    count++;
    }
    }
    }
    if (count>0)
    return (false);

    Thanks in advanced

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,385
    1. When posting code, use forum BB Code tags to wrap your code with.
    2. Web form, what about the HTML you are using?

    Checking multiple words, you have a nested loop and a loop to run through the words, if its only working on the first word, your logic is faulty. I would say that a regular expression would be much faster way of testing if any matches are found as you can specify a case insensitive search that doesn't care if Your Capitalized, cAmEl CaSe or not.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Jun 2017
    Posts
    8
    Hi, very sorry for not using BB code tags, very new to all this.
    I have multiple words in the badword list and all work as a single word but if input has more than the badword it posts as ok. How do I include a regular expression?

    I can only get the client inputted text from
    PHP Code:
    var fields=document.getElementsByTagName('INPUT'); 
    So, is it possible to modify whats already there, if so, what do I need to add?
    If not, what do I need to do bearing in mind I can only get the client inputted text from
    PHP Code:
    document.getElementsByTagName('INPUT'); 

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,385
    You use CODE for plain text and JavaScript, PHP and HTML art obvious.

    As for the code you posted, where is the HTML?
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  5. #5
    Join Date
    Jun 2017
    Posts
    8
    Hi,
    What is "art obvious"
    I'm a newbie, I'm not aware of HOW to use [CODE]/[PHP], the code is from a php file If you want to be pedantic and not helpful you have succeeded.

    There is no HTML, its CODE, the client input is the str
    PHP Code:
    var fields
    , but hey-oh, I see you have better things to do than try to be helpful towards a newbie.
    Continue to point out right & wrong methods of posting CODE PHP HTML, not helpful unless your boosting your own posts, presence and righteousness.

    I will search other helpful forums for genuine help.
    I hope you are just the minority and other newbies will see this and not tar webdeveloper.com with your dirty brush. Have a good day.

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,385
    You don't seem to understand, your page will be HTML and you have JavaScript, you have only posted a couple of lines of JavaScript but no HTML markup is included.

    As for "art" its meant to be "are".

    FYI, this is not a forum that is for code requests, it is to help people with code problems and people wanting help are helpful with posting the code they have problems with, I have asked three times now but you are reluctant to provide anything to help you with and until you do, you will not get many responses.

    If you are going to cross post in other forums, then good luck, you will be expected to provide something to get help with.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  7. #7
    Join Date
    Jun 2017
    Posts
    8
    Hi \\.\
    You've only asked twice, I'm not reluctant as you kindly divert the issue, the "couple of lines of javascript" when inserted into my page "WORKS" with a single word and the alerts, clearly mentioned several times above. The javascript is in the middle of a load of PHP, there is No HTML. again mentioned. You know best.

    If it makes you feel better to use "CROSS POST" I don't expect anything more from you, hence the clean mkove to other methods you "are obviously" not a goto guy, more jump through hoops.
    I've had a brilliant response elsewhere with the exact same request...... with the str & alert from these couple of lines of javascript

    I must thank you for your time wasting, with a little effort and thought, you could/maybe/possibly have helped eventually. Another 3 posts to your credit. Two replies (14 minutes) elsewhere and now fully functional, it wasn't difficult.

  8. #8
    Join Date
    Oct 2013
    Location
    Sheboygan, Wisconsin
    Posts
    1,609
    Then post the fix so the next person who hits the problem can find it.

  9. #9
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,385
    Quote Originally Posted by hudds-phil View Post
    Hi \\.\
    You've only asked twice, I'm not reluctant as you kindly divert the issue, the "couple of lines of javascript" when inserted into my page "WORKS" with a single word and the alerts, clearly mentioned several times above. The javascript is in the middle of a load of PHP, there is No HTML. again mentioned. You know best.

    If it makes you feel better to use "CROSS POST" I don't expect anything more from you, hence the clean mkove to other methods you "are obviously" not a goto guy, more jump through hoops.
    I've had a brilliant response elsewhere with the exact same request...... with the str & alert from these couple of lines of javascript

    I must thank you for your time wasting, with a little effort and thought, you could/maybe/possibly have helped eventually. Another 3 posts to your credit. Two replies (14 minutes) elsewhere and now fully functional, it wasn't difficult.
    The point you seem to be missing is that this site is like many other sites, you need to provide something in order to get something back. I wasn't the one hindering you, it was yourself that was doing an eloquent job of that.

    Good Day.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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