Created
January 15, 2019 14:04
-
-
Save dampee/297771226f939cbae8231485a4e5c2f5 to your computer and use it in GitHub Desktop.
Clean azure blob storage container name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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