I'd like to use .indexOf to search between a range of characters in text submitted by a user, but I'm not sure how I would go about it.
Let's say: myText = "abcd" and I wanted to search to see if the "ab" existed ONLY at the start, and ONLY up to the 2nd character.
if "ab" is present within the first 2 characters, then "do stuff"
If myText = "abab" I would only want it to recognize the 1st "ab" and execute a command based on that.
I would then like to search between the 3rd and 4th character within another indexOf command. etc.
so far I'm only able to do the following:
myText = "abab"
if (myText.indexOf("ab") > -1) alert("Found first 'ab'");
Any ideas?