Azure Queue Naming Syntax, Limitations & Validation

Windows Azure has some specific naming criteria for queue names, and scant error messages to tell you when you’ve tried to create a queue that hasn’t followed syntax. 

There is a quick module online in C# from Neil Kidd of Microsoft, that does some validation of your queue names. Below, I’ve refactored it to VB.NET.


 Shared Sub ValidateAzureQueueName(ByVal name As String)

        If (String.IsNullOrEmpty(name)) Then
            Throw New ArgumentException("A queue name can't be null or empty", "name")
        End If

        'A queue name must be from 3 to 63 characters long.
        If (name.Length < 3 Or name.Length > 63) Then
            Throw New ArgumentException("A queue name must be from 3 to 63 characters long", "name")
        End If

        ' The dash (-) character may not be the first or last letter.
        ' we will check that the 1st and last chars are valid later on.
        If Left(Trim(name), 0) = "-" Or Right(Trim(name), 0) = "-" Then
            Throw New ArgumentException("The dash (-) character may not be the first or last letter", _
                                        "name")
        End If

        ' A queue name must start with a letter or number, and may
        ' contain only letters, numbers and the dash (-) character
        ' All letters in a queue name must be lowercase.
        For Each ch As Char In name

            If (Char.IsUpper(ch)) Then
                Throw New ArgumentException("Queue names must be all lower case", _
                                            "name")
            End If

            If (Not (Char.IsLetterOrDigit(ch)) And ch <> "-") Then
                Throw New ArgumentException("A queue name can contain only letters, numbers and dash(-) characters", _
                        "name")
            End If
        Next

    End Sub

About the Author