0

I need a regex to validate a URL with conditions below:

Ex:

www.google.com

www.google.com/[any_params]

http://google.com/[any_params]

https://google.com/[any_params]

google.com/[any_params]

I used this regex:

/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/

but it's returning false with this case: www.google.com

or returning true with this case: http://i.stack.imgur.com/X2JZC.png

Thanks for your help!

BuZZ-dEE
  • 4,936
  • 10
  • 57
  • 84
s7ven
  • 163
  • 1
  • 2
  • 11

1 Answers1

-1

The following regular expression should work for you:

var regex = /^(ftp:\/\/|http:\/\/|https:\/\/)?(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!-\/]))?$/;
AlliterativeAlice
  • 10,893
  • 8
  • 45
  • 68