<input> tag validation for URL
In html5 you can use the tag input type="url":
<input type="url" />
you can use your own pattern too:
<input type="url" pattern="https?://.+" required />
In the paper Uniform Resource Identifier (URI): Generic Syntax [RFC3986] http://www.ietf.org/rfc/rfc3986.txt the regular expression for a URI is:
^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
For example, matching the above expression to
http://www.ics.uci.edu/pub/ietf/uri/#Related
results in the following subexpression matches:
$1 = http: $2 = http $3 = //www.ics.uci.edu $4 = www.ics.uci.edu $5 = /pub/ietf/uri/ $6 = <undefined> $7 = <undefined> $8 = #Related $9 = Related
Does it make sense that the url is valid without a protocol?
For instance, currently http://google.com
is a valid url, while google.com
is not.
Similarly, http://localhost
is a valid url, while localhost
is not a valid url.