public static boolean isValidName(String text)
{
Pattern pattern = Pattern.compile("^[^/./\\:*?\"<>|]+$");
Matcher matcher = pattern.matcher(text);
boolean isMatch = matcher.matches();
return isMatch;
}
Does this method guarantee a valid filename on Windows?
Given the requirements specified in the previously cited MSDN documentation, the following regex should do a pretty good job:
Note that this regex does not impose any limit on the length of the filename, but a real filename may be limited to 260 or 32767 chars depending on the platform.