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()))
j08691
  • 197,815
  • 30
  • 248
  • 265
rjimenez
  • 58
  • 1
  • 5

1 Answers1

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

Avinash Raj
  • 166,785
  • 24
  • 204
  • 249
  • it is the answer, thanks bro. I spent more than 1 hour searching what is wrong. Thanks a lot for your answer – rjimenez Jul 21 '14 at 16:52