-1

I need a regex to validate both default link formats in client side. For example http://example.com and #myInternalLink are valid. I wrote this but not working.

^(((http|https)://(([A-Z0-9][A-Z0-9_-])(.[A-Z0-9][A-Z0-9_-])+)(?::\d{1,5})?(?:$|[?/#])) | (#([A-Z0-9][A-Z0-9_-]*)))

Already answered question just solves default link formats.I want to validate both http://example.com and #myInternalLink in a same regex

Mahsa
  • 329
  • 1
  • 3
  • 12

1 Answers1

-1

Have a look at https://www.rfc-editor.org/rfc/rfc3986 for what valid URLs are. In regards to your regular expression, have a look at What is a good regular expression to match a URL?

Community
  • 1
  • 1
D.R.
  • 18,900
  • 20
  • 82
  • 181