Can javascript accurately determine whether a URL link address is valid?

can javascript accurately determine whether a URL link address is valid?

can 1.javascript accurately determine whether a URL link address is valid?

2. "^ [A-Za-z] +: / / [A-Za-z0-9murf _] +\. [A-Za-z0-9murf% salary] + $"

3.ajax request

do you have anything better besides these three?

Mar.11,2021

new URL ()


I don't know what you mean by "valid", whether you can only open this link, or whether it is a legitimate url
1. If you judge whether it is a legal url, then you can do
2 with regular. If it is judged to be able to open it, then we can only use ajax


it is troublesome to judge whether a URL (or, more accurately, a URI) is grammatically valid, knowing that URL can correspond to many protocols (not just http or https),). A qualified URL is made up of

.
://[:]/[][?]

this constitutes, in addition to the protocol and host other are optional, and in theory after encoding to support all characters (in fact, do not encode some special characters are sometimes valid), in addition, if the document is relatively linked to the URL, then the protocol and the host is also omitted.

it is too flexible to directly judge whether URL is valid in format.

in addition, it means to judge whether the resource referred to by URL is available, which requires a technology similar to ajax. You can refer to link description

.
Menu