I want a text to be colored when I type "hello", "Hello", "HELLO", ect.. in an input, it works when I use a string but not as a regex
<input id="input" type="input" value="hello"/>
<span id="result">Hello</span>
<script>
var input = document.getElementById('input');
var result = document.getElementById('result');
function greenTheTitle(){
result.style.color = 'green';
}
function redTheTitle(){
result.style.color = 'red';
}
input.addEventListener('keyup', function goodMrn(){
var inputValue = input.value;
if(inputValue == /hello/i ){ //does'nt work here
greenTheTitle();
}
if(inputValue != /hello/i ){ //and here
redTheTitle();
}});
</script>
</body>
</html>
if(inputValue == "hello" )
works
but
if(inputValue == /hello/i )
doesn't