-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate isURL if it contains a TLD *or* a protocol #635
Comments
Why not just: if (validator.isURL(url, {require_tld: true}) ||
validator.isURL(url, {require_protocol: true}) {
// render as URL
} |
Well this is definitely an option but requires parsing same input twice. Doing twice more work is not always a good idea performance-wise when trying to decide how to display a few thousands pieces of text on a page. |
I am having a similar issue. For me it seems that
I am using version 9.1.2, and have tested it both locally (node 8.7.0) and on https://npm.runkit.com/validator |
@mncrff I am having the same issue... Why is "http://www.ddd" valid when I pass in {require_tld: true} ??? validator.isURL('http://www.ddd', { that should fail, but doesn't. Any fix or reason why it's returning true? |
bueller bueller? |
@tsx - remember that that work still has to be done by the end of the day, either by the library or library's end-user. I don't see any perf gains here. |
tl;dr: There should be a way to validate isURL if it has a TLD or a protocol part, or both. For example:
Use case: I use isURL validation to determine if a user-provided string is an URL or not. Based on that, I render that string either as a hyperlink or plain text. Being user-friendly, I allow URLs to be typed without protocol, assuming implicit http:// in that case. However, sometimes users want to link to their servers on a local network, referencing them by just a hostname, like "http://localhost". To avoid rendering any single word as a link, I'd like a valid URL to have at least one of URL features: either a TLD (like .com) or a protocol (like "http://").
I know that there are
require_tld
andrequire_protocol
options, but if I set both to false, it will see any single word like "domain" as a valid URL, which is not the case.The text was updated successfully, but these errors were encountered: