Skip to content

Instantly share code, notes, and snippets.

@restlessmedia
Created July 25, 2014 10:08
Show Gist options
  • Save restlessmedia/1356aea6367ce20a3392 to your computer and use it in GitHub Desktop.
Save restlessmedia/1356aea6367ce20a3392 to your computer and use it in GitHub Desktop.
Azure container name validation
public static class Validator
{
public static bool IsValidName(string name)
{
if (string.IsNullOrEmpty(name))
return false;
const string rootName = "$root";
if (name.Equals(rootName))
return true;
if (name.Length < 3 || name.Length > 63)
return false;
const string pattern = @"^[a-z0-9](([a-z0-9\-)){1,61}[a-z0-9]$";
// todo - check for consecutive hyphens
return Regex.IsMatch(name, pattern);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment