public static boolean isValidName(String text)
{
Pattern pattern = Pattern.compile(\"^[^/./\\\\:*?\\\"<>|]+$\");
Matcher matcher = pattern.matcher(text
Posting a new answer because I dont have the rep threshold to comment on Eng.Fouad's code
public static boolean isValidName(String text)
{
try
{
File file = new File(text);
if(file.createNewFile()) file.delete();
return true;
}
catch(Exception ex){}
return false;
}
A small change to your answer that prevents deleting a pre-existing file. Files only get deleted if they were created during this method call, while the return value is the same.