I have a page where the user is asked his name.
After typing it in a textbox, a reply will show up, using the value from the textbox to greet the user.
If the user just types his name, everything is fine, but if he types something like "My name is John", the reply will be "Hello, my name is john! Nice to meet you!", which I don't want to happen.
Is there a way to get the user input, but to exclude some words, like "my", "name", "is"...
This is what I have:
function myFunction() {
var text;
var answer = document.getElementById("myInput").value.toLowerCase();
answer = answer.replace(/[^a-z0-9\s]/g, "");
switch(answer) {
case "":
text = "Please type something.";
break;
default:
text = "Hello, " + answer + "! Nice to meet you!";
}
document.getElementById("reply").innerHTML = text;
}
<p>What is your name?</p>
<input id="myInput" type="text">
<button onclick="myFunction()">Go</button>
<p id="reply"></p>