2

Please advice how to validate a url that should have http or https and www in it

Thanks Amit

2
  • 1
    Sorry, but have you tried to search Commented Jul 21, 2011 at 13:36
  • yes, what i couldn't find is a script that checks for both http and www Commented Jul 21, 2011 at 13:38

4 Answers 4

4

Try to use that function:

(function isURL(s) {
    var regexp = /http(s?):\/\/www\.[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
     return regexp.test(s);
})("https://www.google.com")

you may play with it here

Sign up to request clarification or add additional context in comments.

1 Comment

This fails for http://www.google.co.uk/. I honestly think your regexp is too extensive.
0

Try this one:

 ^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?



var re = /^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;

alert(re.test(yourString));

Test it at this JsFiddle.

Found at RegExLib.

Comments

0

you could use:

function checkhttpWww(s) {
     var reg = /http(s?):\/\/www/;
      return reg.test(s);
}

Comments

0
function is_correct(x) {
    return /^http[s]?:\/\/www\./.test(x);
}

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.