Achilles.Acme.Storage.Azure.FileNameHelpers.IsValid C# (CSharp) Method

IsValid() public static method

Check if a blobname(blob or virtual directory) is valid
public static IsValid ( string sFileName ) : bool
sFileName string blob name
return bool
        public static bool IsValid( string sFileName )
        {
            //A blob name must be at least one character long and cannot be more than 1,024 characters long
            if ( ( sFileName.Length == 0 ) || sFileName.Length > 1024 )
                return false;

            //A blob name can contain any combination of characters, except reserved URL characters
            //Notice: '/' is a URL reserved char, but in Azure blob can be used for virtual dir
            string validSpecialChars = @"$-_.+!*'()/";

            foreach ( char c in sFileName )
            {
                if ( !( char.IsLetterOrDigit( c ) || validSpecialChars.IndexOf( c ) >= 0 ) )
                    return false;
            }

            return true;
        }