0

I have this code:

var textarea = document.getElementById('myTextarea');
var tag = '<!DOCTYPE html>';
var textValue = textarea.value;

if (textValue.indexOf(tag) != -1) {
  document.getElementById('status').innerHTML = "match found";
} else {
  document.getElementById('status').innerHTML = "no match found";
}

I’m trying to get indexOf to match tag no matter if the var tag is in upper-case or lower-case. How can I go about doing this?

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75

1 Answers1

2

use toUpperCase() like this

var textarea = document.getElementById('myTextarea');
var tag = '<!DOCTYPE html>';  
var textValue=textarea.value;

if (textValue.toUpperCase().indexOf(tag.toUpperCase())!=-1)
{
   document.getElementById('status').innerHTML = "match found";
} else {
       document.getElementById('status').innerHTML = "no match found";
} 

This way the condition compares both as upper case even if one of them is lower case, hence case insensitive