private boolean isValid(final String string, final int selected) {
    if ((((getFormattedTextField().getText().length() - selected) + string.length()) > MAX_CHAR)
        || (string.indexOf("\\") > -1)
        || (string.indexOf("/") > -1)) {
      invalidEdit();
      return false;
    }

    final File file = new File(m_directory.getPath() + File.separator + string);

    if (!file.exists()) {
      try {
        if (!file.createNewFile()) {
          invalidEdit();
          return false;
        }
        file.delete();
      } catch (final IOException e) {
        invalidEdit();
        return false;
      }
    }

    return true;
  }
Filter for JFormattedTextField. Ensures valid filenames. Does not work for directories.

@param directory Directory where a file with the specified filename is temporarily created for
    validation purpose. http://stackoverflow.com/questions/893977/java-how-to-find-out-whether
    -a-file-name-is-valid
java/zylib/src/main/java/com/google/security/zynamics/zylib/gui/CFilenameFormatter.java