Wednesday, December 17, 2008

Check a value in a string using Javascript

In .net if we want to check a value whether it is existing in given string
we have contains function which return true or false.
But in javascript we dont have function like this.But we can implement this
by using the function indexOf()

All you need to do is check whether the return value is -1 or not. A return value of -1 implies that the specific letter is not present in the given string.

function checkString()
{
if(str.indexOf("http://")==-1)
{
alert("Value Not Found");
}
else
{
alert("Value Found");

}
}

No comments: