0

I have this url:

http://thisjs.blogspot.co.il/2015/01/blog-post_7.html

And in javascript i have this pattern to check for it's validity, which returns false for some reason, what is missing here?

var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
            '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
            '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
            '(\\:\\d+)?(\\/[-a-z\d%_.~+#!]*)*'+ // port and path
            '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
            '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
            if(!pattern.test(str)) {
                return false;
            } else {
                return true;
            }

I want true on the url i mentioned above? where do i look first?

1 Answer 1

1

You need to have:

'(\\:\\d+)?(\\/[-a-z\\d%_.~+#!]*)*'+ // port and path

i.e. \\d instead of \d otherwise you are just matching literal d instead of a digit.

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

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.