Re:In search of the perfect URL validation regex (2010)
by mercora on Saturday September 25, 2021 @03:21PM
(#28655535)
while not terribly important or outright not required this fails (treats urls as regex) for link-local addresses with device identifier (zone-id) applied like "[fe80::8caa:8cff:fe80:ff32%eth0]" although that would need to be fixed in the standard if its desired :)
i've found some reasoning[0] as to why its not supported with browsers in mind though.
At Transcend, we need to allow site owners to regulate any arbitrary network traffic, so our data flow input UI¹ was designed to detect all valid hosts (including local hosts, IDN, IPv6 literal addresses, etc) and URLs (host-relative, protocol-relative, and absolute). If the site owner inputs content that is not a valid host or URL, then we treat their input as a regex.
I came up with these simple utilities built on top of the URL interface standard² to detect all valid hosts & URLs:
• isValidHost: https://gist.github.com/eligrey/6549ad0a635fa07749238911b429...
Example valid inputs:
• isValidURL (and isValidAbsoluteURL): https://gist.github.com/eligrey/443d51fab55864005ffb3873204b...Example valid inputs to isValidURL:
1. https://docs.transcend.io/docs/configuring-data-flows2. https://developer.mozilla.org/en-US/docs/Web/API/URL