0

here is my regexp

var url_reg = /^(http[s]?:\/\/|ftp:\/\/)?(www\.)?[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|in|au)+/;

it works fine for single input like https://www.google.com , but
it allows double or more "http/https/www" like below -

https://www.google.com/https://www.google.com/

url can also include folder like google.com/folder/file

i need to validate single occurrence of valid url.

Can anyone help me?

1 Answers1

0

To validate a URL, you can use a regex. This is what I use. A valid URL per the URL spec. The URL you have provided, is actually a valid URL per the URL spec.

/^((((https?|ftps?|gopher|telnet|nntp):\/\/)|(mailto:|news:))(%[0-9A-Fa-f]{2}|[-()_.!~*';\/?:@&=+$,A-Za-z0-9])+)([).!';/?:,][[:blank:]])?$/

This was borrowed from OSWAP

Ryan
  • 14,392
  • 8
  • 62
  • 102