Created
July 25, 2014 10:08
-
-
Save restlessmedia/1356aea6367ce20a3392 to your computer and use it in GitHub Desktop.
Azure container name validation
This file contains 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 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