Skip to content

Instantly share code, notes, and snippets.

@dampee
Created January 15, 2019 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dampee/297771226f939cbae8231485a4e5c2f5 to your computer and use it in GitHub Desktop.
Save dampee/297771226f939cbae8231485a4e5c2f5 to your computer and use it in GitHub Desktop.
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