9

Is there already a javascript function/library/snippet written for the validation of the RFC 1738 URL specifications listed at http://www.ietf.org/rfc/rfc3986.txt?

Tingting
  • 109
  • 1
  • 5

2 Answers2

5

From http://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/plugin/uri.js

Implements RFC 3986 for parsing/formatting URIs.

You can find usage examples in the unit tests.

Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
4

No, but I've written an article that covers the related RFC-3986 (which updates 1738):

Regular Expression URI Validation

I've set up the article so that you can double-click on any of the regexes to get a correctly formatted snippet for a variety of languages.

ridgerunner
  • 33,777
  • 5
  • 57
  • 69
  • i mean yes you've provided the regex for each part but how do i combine them to form the full thing? – Tingting Jul 07 '11 at 04:32
  • @Tingting: The regexes towards the end of the article (i.e. `absolute-URI`, `URI` and `relative-ref`) _do_ validate a complete URI. However, these do not validate that the domain is valid with respect to the DNS naming convention. I've written a function in PHP to validate absolute HTTP/FTP URLs. You can see it [here](http://stackoverflow.com/questions/6191720/regular-expression-to-match-generic-url/6202972#6202972). I have not created a javascript version yet. – ridgerunner Jul 07 '11 at 15:13