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: https://i.stack.imgur.com/X2JZC.png

Thanks for your help!

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
s7ven
  • 173
  • 1
  • 2
  • 12

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
  • 11,841
  • 9
  • 52
  • 69