Regular expression for validating url in javascript

" - I'm not sure why that's in the gist above, I'd think it would fail on a JS unit test also. I did make one change: the "-*" in both domain and host was (incorrectly) succeeding against " so I changed it to "-? Hi, is a valid URL but the last dot ist usually not written by convention. works in Firefox and IE Just a small comment about brodcast and network address. Ex: If a provider have two class like and, they can combine the two in a classless network: // Regular expression for URLs // Based on // Improved to only pickup links begining with http https ftp ftps mailto and www $regex = "_(? The above is also true for decimal notations, various forms of IPV6 URLs and other "non-human" URLs. Following link might help you [link= You can use the URL regular expression at the place of the regular expression used in above example. But I'd consider it a good starting point with fewer false positives, and it also matches all the common URL's in this question. Many thanks to @Etai G for the help and the suggestions to resolve the problem. Anyway your change fix that if it becomes necessary for some reader.

$_iu S I have added simple network ranges validation, the rules I used are: - valid range -, network adresses above and including are reserved addresses - first and last IP address of each class is excluded since they are used as network broadcast addresses since I don't think this is worth implementing completely in a regular expression, a following pass should exclude the Intranet address space: - - 1.255 - the loopback and the automatic configuration address space: - - while the local, multicast and and the reserved address spaces: - (SPECIAL-IPV4-LOCAL-ID-IANA-RESERVED) - 239.255.255 (MCAST-NET) - (SPECIAL-IPV4-FUTURE-USE-IANA-RESERVED) should already be excluded by the above regular expression. This has been written to validate URLs typed by users and/or found in log files. :\x22|\x5b\x2f|\x3c\x2f) haven't tried it, not sure it does exactly what you asked/depicted. I'd like to let through URL's without the protocol specified (HTTP(S) or FTP). @nghuuphuoc, the regexp already supports international URLs, just write them using natural UTF-8 encoding. Negative lookahead is used instead NOTE, that package does fuzzy search, not strict validation. If they copy it out and back into a browser so they may not know what's wrong with it upon visual inspection.

In that network, and are two valid and usable address. " (string contains double quotes) ' (string contains single quote) [ (string contains brackets) here is JS demo with full unicode support, including astral characters. Src is here: Since astral characters take 2 positions, [^negative] class is impossible. some=query while they may not technically be valid, it is something I could see a user typing and most browsers will fix it for them. The only pattern it won't match for me (Using it in a Java Regex) is where the IP address is '0'(ZERO) padded, like: I get as input from other tools. Public Sub Match Url(url As String) Dim rxs As String = "" 'protocol identifier rxs = rxs "(?

:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9] )*(?

Regular expression for validating url in javascript comments

  • Javascript - What do you think of my regex for URL validation. profil de paulette60


    Your regex has many false positives matches without a valid URL being there, and many false negativs URLs you don't recognize. You should read the appropriate RFCs which contain relevant parts of the grammar. Here are some failure scenarios ⊖ You don't match schemes other than HTTP or.…