Skip to content

Is My Azure Blob Storage Container Name Valid?

Updated: at 11:18 PM

I just spend about 2 hours wrestling with what turned out to be an invalid blob storage container name.  I named a container “MyTest1” which did not meet the criteria.  For your information, the criteria is as follows:

  1. 3 to 63 Characters
  2. Starts With Letter or Number
  3. Letters, Numbers, and Dash (-)
  4. Every Dash (-) Must Be Immediately Preceded and Followed by a Letter or Number
  5. Blob filenames must be lowercase (no uppercase letters are valid)

So, I decided to hunt for a regular expression to do this and I found one on the web. I’m not sure if it’s correct, but here is what I found at http://social.msdn.microsoft.com/Forums/en-GB/windowsazuredata/thread/d364761b-6d9d-4c15-8353-46c6719a3392 from Gaurav Mantri (method that includes the regex).

 

internal static bool IsBlobContainerNameValid(string name)
    {
      if (name.Equals("$root"))
      { 
        return true; 
      }
      string validBlobContainerNameRegex = @"^([a-z]|\d){1}([a-z]|-|\d){1,61}([a-z]|\d){1}$";
      Regex reg = new Regex(validBlobContainerNameRegex);
      if (reg.IsMatch(name))
      {
        return true;
      }
      return false;
    }

 

Hope this helps!