0

I need to check if a string starts with http:// in java script

What I have is

if(!txt.match(/^http:/)) {}  // this only works for http:

I need to make it work for http://

can any one suggest a solution please?

2 Answers 2

2

Alternatively:

txt.substr(0, 7) === "http://"
Sign up to request clarification or add additional context in comments.

Comments

1

You need to escape \ chars, also for checking is better to use test method.

if(!(/^http:\/\//.test(txt))) {}

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.