code: public static void validateSpaceId(String spaceID)
          throws InvalidIdException {
          if (spaceID == null ||
              spaceID.trim().length() < 3 ||
              spaceID.trim().length() > 42) {
              String err = "Space ID must be between 3 and 42 characters long";
              throw new InvalidIdException(err);
          }
  
          if (!spaceID.matches("[a-z0-9.-]*")) {
              String err = "Only lowercase letters, numbers, periods, " +
                           "and dashes may be used in a Space ID";
              throw new InvalidIdException(err);
          }
  
          if (spaceID.startsWith(".") || spaceID.startsWith("-")) {
              String err = "A Space ID must begin with a lowercase letter.";
              throw new InvalidIdException(err);
          }
  
          if (spaceID.matches("[0-9]+[a-z0-9.-]*")) {
              String err = "A Space ID must begin with a lowercase letter.";
              throw new InvalidIdException(err);
          }
  
          // This rule is required to conform with the spec for a URI host name,
          // see RFC 2396.
          if (spaceID.matches("[a-z0-9.-]*[.][0-9]+[a-z0-9-]*")) {
              String err = "The last period in a Space ID may not be " +
                           "immediately followed by a number.";
              throw new InvalidIdException(err);
          }
  
          if (spaceID.endsWith("-")) {
              String err = "A Space ID must end with a lowercase letter, " +
                           "number, or period";
              throw new InvalidIdException(err);
          }
  
          if (spaceID.contains("..") ||
              spaceID.contains("-.") ||
              spaceID.contains(".-")) {
              String err = "A Space ID must not contain '..' '-.' or '.-'";
              throw new InvalidIdException(err);
          }
  
          if (spaceID.matches("[0-9]+.[0-9]+.[0-9]+.[0-9]+")) {
              String err = "A Space ID must not be formatted as an IP address";
              throw new InvalidIdException(err);
          }
      }
docs: Determines if the ID of the space to be added is valid
  
  @throws InvalidIdException if not valid