tech_soul8;1295173 wrote:Hope this is what you're looking for:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script>
function testLetter(string,pattern)
{
for (var i = 0; i < pattern.length; i++)
{
var tmpChar = pattern.charAt(i);
if (string.indexOf(tmpChar) == -1) return false;
}
return true;
}
</script>
</head>
<body>
</body>
</html>
Hey, I tried the code but it didn't work too well. Its meant to show true, true, false but it showed false, false, false.
I changed some things but it still gives me pretty much the same answer.
This gives me true, true, true
function match(string,pattern)
{
var
index = true,
i;
for (i = 0; i < pattern.length; i++) {
if (pattern.toLowerCase().indexOf(string) !== -1) {
index = i;
break;
}
}
return index;
}
alert(match("abcdef","@C2D!"));
alert(match("abcdef","CAfe"));
alert(match("abcdef","CG"));
and this gives me false false false
function match(string,pattern)
{
for (var i = 0; i < pattern.length; i++)
{
var tmpChar = pattern.charAt(i);
if (string.indexOf(tmpChar) == -1) return false;
}
return true;
}
alert(match("abcdef","@C2D!"));
alert(match("abcdef","CAfe"));
alert(match("abcdef","CG"));