Reg Exp
Web Design
Notes Client
Is Valid Notes ID
This JavaScript regular expression will validate a Notes ID. To use the function, call "isValidNotesID" and pass in the Notes ID to be checked and an optional parameter of the number of slashes that should be in the ID. If the parameter is omitted, it defaults to 1 slash. For example, if the ID is supposed to be in the format of "John Doe/MyCompany", then you can call isValidNotesID(myString). But if the format is supposed to be "John Doe/MyCity/MyCompany", then you'll need to call isValidNotesID(myString, 2).

According to the Domino Administrator, valid characters in Notes names are letters, numbers, ampersand (&), hyphen (-), apostrophe ('), period (.), space, and underscore (_). To verify this, go to the Domino Administrator and attempt to register a user with some invalid characters. You'll get this message.

The regular expression works by building a regular expression string based on how many slashes are desired. The string must start out with one or more valid characters, then there must be one or more valid characters between each slash, and the string must end with one or more valid characters. Note that you could validate a "flat" Notes ID (no slashes) with this function as well. The regular expression string in the case of a "flat" Notes ID would check for one or more characters at both the beginning and end of the string.

function isValidNotesID(notesID, numSlashes) {
   if (notesID.length == 0) { return false; }
   if (typeof notesID != "string") { return false; }
   if (!numSlashes) { numSlashes = 1; } else { numSlashes = parseFloat(numSlashes); }
   if (typeof numSlashes != "number") { numSlashes = 1; }
   var allowedChars = "[\\w &'\\-\\.]+";
   var regExpString = "^" + allowedChars;
   for (var i=0; i<numSlashes; i++) {
      regExpString += "\\/" + allowedChars;
   regExpString += "$";
   var r = new RegExp(regExpString);
   return r.test(notesID);