I have the following snippet running cute:
function busca() {
var str = document.getElementById('txt').value;
if(document.getElementById(str))
console.log(str + ' existe.');
else
console.log(str + ' ñ existe');
}
<input type="text" id="txt"><input type="button" value="mais" onclick="busca()">
<pre>Ex.: vaca, boi, porco ou galinha</pre>
<div id='vaca'></div>
<div id='boi'></div>
<div id='porco'></div>
<div id='galinha'></div>
Now I want to deal with some more details ...
Let's suppose that in the HTML document there are other id
segmented like this:
id='vaca-leiteira'
id='boi-nelore'
id='Porco_granja'
id='gaLinha_caIpirA'
Note that we have their designation followed by a hyphen or underline , and having some variations between "vowels" and "consonants" being uppercase and / or lowercase .
How can I resolve this when typing in the text field? Type:
-
Dairy cow
-
Chicken hen
In all the charade is, ignore these points and bring the final result. Would you have to use some
RegExp
?