2

May be stupid Q for you. I am getting URL by using document.URL

Now i want to check whether that URL contain my input string or not.

Is ther any way to do this or I have to go for manual process.?

would be grateful for help.

2 Answers 2

4

There are several ways to check. document.URL is a String, so you can use for example:

 //use indexof
 document.URL.indexOf('this is my input string') > -1;

 //use the String.search method (equivalent to indexOf)
 document.URL.search('this is my input string') > -1

 //use a regular expression with method 'test'
 /this is my input string/i.test(document.URL);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use indexOf() Method to return the position of the first occurrence of a specified value in a string.

Or, use search() Method with a regular expression. Which is much more powerful.

Check the info in w3school:

http://www.w3schools.com/jsref/jsref_indexof.asp

http://www.w3schools.com/jsref/jsref_search.asp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.