Search code examples
androidfiledirectorypathandroid-file

Checking If Folder Name is valid


I am creating a folder in android's internal storage by using the below code-

File file=new File(this.getFilesDir()+"/"+FolderNamefromEditTextasString);
file.mkdir();

I am getting the folder name from an Edit Text. I want to know how to check if the folder name is valid or not before creating. I don't exactly know which characters should not be there in a valid folder name. I first would like to validate the string from edit text. Also, I don't like to have spaces and "." in folder name string.


Solution

  • use regular expressions to test if it is something valid. I guess you can allow numbers, letters - and it can be ok not to allow special characters (such as ë,@ and other) something like [0-9a-zA-Z/-+]+ should work just fine