Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if userinput is a valid URI in XUL

Is there a built-in function/method that can check if a given string is a valid URI or not in the Mozilla XUL toolkit? I have looked for one but found none, but since this is my first time using XUL and its documentation it could be that I just overlooked it. So I'm just making sure before I start writing my own IsValidURI function.

like image 456
KCasier Avatar asked Aug 29 '08 06:08

KCasier


1 Answers

The nsIIOService.newURI(...) method is what you're looking for. It throws NS_ERROR_MALFORMED_URI if the URI string is invalid.

Example:

try {
  var ioServ = Components.classes["@mozilla.org/network/io-service;1"]
                         .getService(Components.interfaces.nsIIOService);
  var uriObj = ioServ.newURI(uriString, uriCharset, baseURI);
} catch (e) {

  // catch the error here

}
like image 136
David Crow Avatar answered Sep 30 '22 06:09

David Crow