0

I have a problem with a regular expression, I tested that in some websites and it is working but when I use that regular expression in the project it is not matching with the correct result. the regular expression is the following

^(http|https)\://(www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$

I need that kind of regular expression because I need validate something like that:

http://www.test.com
https://www.test.com/login

the code that I am using is the following

var pattern = new RegExp(URL_REGEXP);
if (pattern.test($('input.editValueText').val()))
2

1 Answer 1

2

You forget to add + after the last character class. Your regex would be,

^(http|https):\/\/(www\.)[a-zA-Z0-9-.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9])?\/?([a-zA-Z0-9-._\?\,\'\/\+&%\$#\=~]+)*$

DEMO

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

1 Comment

it is the answer, thanks bro. I spent more than 1 hour searching what is wrong. Thanks a lot for your answer

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.