How can I modify this script so it checks and makes sure it contains the exact string "abc"?
(/^[a].*/i.test(mystring))
It needs to be case insensitive and take lower and upper caps.
Though you can use regex, I feel this is better suited for .toLowerCase & .indexOf:
var hasABC = ("myabcstring".toLowerCase().indexOf("abc") !== -1);
Regex seems like overkill to me.
Answer to a comment:
var mystring = "FoOaBcBaR";
function checkForABC(){
if (mystring.toLowerCase().indexOf('abc') != -1)
alert('found ABC!');
else
alert('Did NOT find ABC');
}
checkForABC();
Just do this:
/^abc$/i.test(mystring);
think the regex expression your looking for is;
^abc$
Hope that helps.
mystringcontainsabcor whether it is equal toabc?