Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Clean azure blob storage container name
public static bool IsValidContainer(string containerName)
// Container names must be valid DNS names, and must conform to these rules:
// * Container names must start with a letter or number, and can contain only letters, numbers, and the dash (-) character.
// * Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.
// * All letters in a container name must be lowercase.
// * Container names must be from 3 through 63 characters long.
// $root is a special container that can exist at the root level and is always valid.
if (containerName.Equals("$root"))
return false;
//if (!Regex.IsMatch(containerName, @"^[a-z0-9](([a-z0-9\-[^\-])){1,61}[a-z0-9]$"))
if (!Regex.IsMatch(containerName, @"^(([a-z\d]((-(?=[a-z\d]))|([a-z\d])){2,62})|(\$root))$")) return false;
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment