Tag Validation For Url
I am trying to validate an URL using JavaScript, but for some reason it's not working. When someone has not entered any URL, it shows message like: Please enter valid URL.(i.e. ht
Solution 1:
In html5 you can use the tag input type="url":
<inputtype="url" />
you can use your own pattern too:
<inputtype="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
Solution 2:
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.
Post a Comment for " Tag Validation For Url"