code: public static void validateSimple(String s, String legal)
              throws URISyntaxException {
          for (int i = 0; i < s.length(); i++) {
              char ch = s.charAt(i);
              if (!((ch >= 'a' && ch <= 'z')
                      || (ch >= 'A' && ch <= 'Z')
                      || (ch >= '0' && ch <= '9')
                      || legal.indexOf(ch) > -1)) {
                  throw new URISyntaxException(s, "Illegal character", i);
              }
          }
      }
docs: Throws if {@code s} contains characters that are not letters, digits or
  in {@code legal}.