since no answer was good enough i did it myself. hope this helps 😉
public static boolean validateFileName(String fileName) {
return fileName.matches("^[^.\\\\/:*?\"<>|]?[^\\\\/:*?\"<>|]*")
&& getValidFileName(fileName).length()>0;
}
public static String getValidFileName(String fileName) {
String newFileName = fileName.replace("^\\.+", "").replaceAll("[\\\\/:*?\"<>|]", "");
if(newFileName.length()==0)
throw new IllegalStateException(
"File Name " + fileName + " results in a empty fileName!");
return newFileName;
}