How to create a javascript/jquery real time check for banned words in an input field
up vote
-1
down vote
favorite
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
add a comment |
up vote
-1
down vote
favorite
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
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
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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
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
jquery real-time
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
add a comment |
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
add a comment |
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()" />
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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()" />
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
add a comment |
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()" />
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
add a comment |
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()" />
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()" />
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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