How to create a javascript/jquery real time check for banned words in an input field











up vote
-1
down vote

favorite
1












I've searched high and low, but just can't find a suitable solution for this issue.... we have an input field in which we don't want people to put certain words. Words such as "unit" or "level" or "apartment" etc...



What we need is a js based real time banned word check that can show a specific error message if we detect the user has typed one of the banned words.



Must be real time so we catch it before they attempt to submit the form.



There are lots of posts on various aspects of this question, but none that seem to match all the elements.



A simple js fiddle example would be very much appreciated.



Thank you in advance.










share|improve this question






















  • Put them in an array....loop through array...check if each word exists in input value...remove if applicable using string methods. Start with a string and an array and get that working...then focus on doing it with the value of an input. Come back when you have some actual code that isn't working as expected
    – charlietfl
    Nov 22 at 1:29












  • Stack overflow isn't here to do your work for you. Post examples of code you've tried.
    – Jacin Tattersall
    Nov 22 at 1:29










  • apologies for spoon-feeding him. it's just that i already have the code from the past asker, i just modified it a bit for him. wont do it again.
    – kapitan
    Nov 22 at 2:01










  • Oh please. Don't apologise for helping a brother out Kapitan. Not everyone's as clever as you, Jacin.
    – starchild
    Nov 22 at 2:27















up vote
-1
down vote

favorite
1












I've searched high and low, but just can't find a suitable solution for this issue.... we have an input field in which we don't want people to put certain words. Words such as "unit" or "level" or "apartment" etc...



What we need is a js based real time banned word check that can show a specific error message if we detect the user has typed one of the banned words.



Must be real time so we catch it before they attempt to submit the form.



There are lots of posts on various aspects of this question, but none that seem to match all the elements.



A simple js fiddle example would be very much appreciated.



Thank you in advance.










share|improve this question






















  • Put them in an array....loop through array...check if each word exists in input value...remove if applicable using string methods. Start with a string and an array and get that working...then focus on doing it with the value of an input. Come back when you have some actual code that isn't working as expected
    – charlietfl
    Nov 22 at 1:29












  • Stack overflow isn't here to do your work for you. Post examples of code you've tried.
    – Jacin Tattersall
    Nov 22 at 1:29










  • apologies for spoon-feeding him. it's just that i already have the code from the past asker, i just modified it a bit for him. wont do it again.
    – kapitan
    Nov 22 at 2:01










  • Oh please. Don't apologise for helping a brother out Kapitan. Not everyone's as clever as you, Jacin.
    – starchild
    Nov 22 at 2:27













up vote
-1
down vote

favorite
1









up vote
-1
down vote

favorite
1






1





I've searched high and low, but just can't find a suitable solution for this issue.... we have an input field in which we don't want people to put certain words. Words such as "unit" or "level" or "apartment" etc...



What we need is a js based real time banned word check that can show a specific error message if we detect the user has typed one of the banned words.



Must be real time so we catch it before they attempt to submit the form.



There are lots of posts on various aspects of this question, but none that seem to match all the elements.



A simple js fiddle example would be very much appreciated.



Thank you in advance.










share|improve this question













I've searched high and low, but just can't find a suitable solution for this issue.... we have an input field in which we don't want people to put certain words. Words such as "unit" or "level" or "apartment" etc...



What we need is a js based real time banned word check that can show a specific error message if we detect the user has typed one of the banned words.



Must be real time so we catch it before they attempt to submit the form.



There are lots of posts on various aspects of this question, but none that seem to match all the elements.



A simple js fiddle example would be very much appreciated.



Thank you in advance.







jquery real-time






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 1:25









starchild

31




31












  • Put them in an array....loop through array...check if each word exists in input value...remove if applicable using string methods. Start with a string and an array and get that working...then focus on doing it with the value of an input. Come back when you have some actual code that isn't working as expected
    – charlietfl
    Nov 22 at 1:29












  • Stack overflow isn't here to do your work for you. Post examples of code you've tried.
    – Jacin Tattersall
    Nov 22 at 1:29










  • apologies for spoon-feeding him. it's just that i already have the code from the past asker, i just modified it a bit for him. wont do it again.
    – kapitan
    Nov 22 at 2:01










  • Oh please. Don't apologise for helping a brother out Kapitan. Not everyone's as clever as you, Jacin.
    – starchild
    Nov 22 at 2:27


















  • Put them in an array....loop through array...check if each word exists in input value...remove if applicable using string methods. Start with a string and an array and get that working...then focus on doing it with the value of an input. Come back when you have some actual code that isn't working as expected
    – charlietfl
    Nov 22 at 1:29












  • Stack overflow isn't here to do your work for you. Post examples of code you've tried.
    – Jacin Tattersall
    Nov 22 at 1:29










  • apologies for spoon-feeding him. it's just that i already have the code from the past asker, i just modified it a bit for him. wont do it again.
    – kapitan
    Nov 22 at 2:01










  • Oh please. Don't apologise for helping a brother out Kapitan. Not everyone's as clever as you, Jacin.
    – starchild
    Nov 22 at 2:27
















Put them in an array....loop through array...check if each word exists in input value...remove if applicable using string methods. Start with a string and an array and get that working...then focus on doing it with the value of an input. Come back when you have some actual code that isn't working as expected
– charlietfl
Nov 22 at 1:29






Put them in an array....loop through array...check if each word exists in input value...remove if applicable using string methods. Start with a string and an array and get that working...then focus on doing it with the value of an input. Come back when you have some actual code that isn't working as expected
– charlietfl
Nov 22 at 1:29














Stack overflow isn't here to do your work for you. Post examples of code you've tried.
– Jacin Tattersall
Nov 22 at 1:29




Stack overflow isn't here to do your work for you. Post examples of code you've tried.
– Jacin Tattersall
Nov 22 at 1:29












apologies for spoon-feeding him. it's just that i already have the code from the past asker, i just modified it a bit for him. wont do it again.
– kapitan
Nov 22 at 2:01




apologies for spoon-feeding him. it's just that i already have the code from the past asker, i just modified it a bit for him. wont do it again.
– kapitan
Nov 22 at 2:01












Oh please. Don't apologise for helping a brother out Kapitan. Not everyone's as clever as you, Jacin.
– starchild
Nov 22 at 2:27




Oh please. Don't apologise for helping a brother out Kapitan. Not everyone's as clever as you, Jacin.
– starchild
Nov 22 at 2:27












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










try this:



i have not created a jsfidlle, all you need to do is copy-paste this on a text file then save it with a .html extension.



<script>
function checkBanWords()
{
var banned_words = ['apple', 'berry', 'citrus'];
var textvalue = document.getElementById('name').value;
for(var i=0; i<banned_words.length; i++) {
if (~textvalue.indexOf(banned_words[i])){

//DO YOUR STUFF HERE

console.log('you have entered a banned word: ' + banned_words[i]);
}
}
}
</script>

<input type="text" name="name" id="name" onkeyup="checkBanWords()" />





share|improve this answer





















  • Thank you - this is exactly what I was trying to do.
    – starchild
    Nov 22 at 1:55










  • glad to help, dont forget to accept this as an answer.
    – kapitan
    Nov 22 at 1:56










  • you're a good man.
    – starchild
    Nov 22 at 2:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422674%2fhow-to-create-a-javascript-jquery-real-time-check-for-banned-words-in-an-input-f%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










try this:



i have not created a jsfidlle, all you need to do is copy-paste this on a text file then save it with a .html extension.



<script>
function checkBanWords()
{
var banned_words = ['apple', 'berry', 'citrus'];
var textvalue = document.getElementById('name').value;
for(var i=0; i<banned_words.length; i++) {
if (~textvalue.indexOf(banned_words[i])){

//DO YOUR STUFF HERE

console.log('you have entered a banned word: ' + banned_words[i]);
}
}
}
</script>

<input type="text" name="name" id="name" onkeyup="checkBanWords()" />





share|improve this answer





















  • Thank you - this is exactly what I was trying to do.
    – starchild
    Nov 22 at 1:55










  • glad to help, dont forget to accept this as an answer.
    – kapitan
    Nov 22 at 1:56










  • you're a good man.
    – starchild
    Nov 22 at 2:31















up vote
1
down vote



accepted










try this:



i have not created a jsfidlle, all you need to do is copy-paste this on a text file then save it with a .html extension.



<script>
function checkBanWords()
{
var banned_words = ['apple', 'berry', 'citrus'];
var textvalue = document.getElementById('name').value;
for(var i=0; i<banned_words.length; i++) {
if (~textvalue.indexOf(banned_words[i])){

//DO YOUR STUFF HERE

console.log('you have entered a banned word: ' + banned_words[i]);
}
}
}
</script>

<input type="text" name="name" id="name" onkeyup="checkBanWords()" />





share|improve this answer





















  • Thank you - this is exactly what I was trying to do.
    – starchild
    Nov 22 at 1:55










  • glad to help, dont forget to accept this as an answer.
    – kapitan
    Nov 22 at 1:56










  • you're a good man.
    – starchild
    Nov 22 at 2:31













up vote
1
down vote



accepted







up vote
1
down vote



accepted






try this:



i have not created a jsfidlle, all you need to do is copy-paste this on a text file then save it with a .html extension.



<script>
function checkBanWords()
{
var banned_words = ['apple', 'berry', 'citrus'];
var textvalue = document.getElementById('name').value;
for(var i=0; i<banned_words.length; i++) {
if (~textvalue.indexOf(banned_words[i])){

//DO YOUR STUFF HERE

console.log('you have entered a banned word: ' + banned_words[i]);
}
}
}
</script>

<input type="text" name="name" id="name" onkeyup="checkBanWords()" />





share|improve this answer












try this:



i have not created a jsfidlle, all you need to do is copy-paste this on a text file then save it with a .html extension.



<script>
function checkBanWords()
{
var banned_words = ['apple', 'berry', 'citrus'];
var textvalue = document.getElementById('name').value;
for(var i=0; i<banned_words.length; i++) {
if (~textvalue.indexOf(banned_words[i])){

//DO YOUR STUFF HERE

console.log('you have entered a banned word: ' + banned_words[i]);
}
}
}
</script>

<input type="text" name="name" id="name" onkeyup="checkBanWords()" />






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 at 1:48









kapitan

34119




34119












  • Thank you - this is exactly what I was trying to do.
    – starchild
    Nov 22 at 1:55










  • glad to help, dont forget to accept this as an answer.
    – kapitan
    Nov 22 at 1:56










  • you're a good man.
    – starchild
    Nov 22 at 2:31


















  • Thank you - this is exactly what I was trying to do.
    – starchild
    Nov 22 at 1:55










  • glad to help, dont forget to accept this as an answer.
    – kapitan
    Nov 22 at 1:56










  • you're a good man.
    – starchild
    Nov 22 at 2:31
















Thank you - this is exactly what I was trying to do.
– starchild
Nov 22 at 1:55




Thank you - this is exactly what I was trying to do.
– starchild
Nov 22 at 1:55












glad to help, dont forget to accept this as an answer.
– kapitan
Nov 22 at 1:56




glad to help, dont forget to accept this as an answer.
– kapitan
Nov 22 at 1:56












you're a good man.
– starchild
Nov 22 at 2:31




you're a good man.
– starchild
Nov 22 at 2:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422674%2fhow-to-create-a-javascript-jquery-real-time-check-for-banned-words-in-an-input-f%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

Sphinx de Gizeh