Hello there, I'm struggling with my computing coursework in college and I though I'd ask here for help.
My issue is simple but I can't get it right.
I need to validate the text into a textbox and check that it contains ONLY alphanumeric characters, but it MUST contain both, not either numeric or alphabetic, but some of each.
The textbox should store information about a Street address, that's why both the street Name and the property Number have to be input. Spaces " " and points "." should also be allowed.
If it helps, something like "12" or "St. Davis Street" should NOT pass the validation checks, whereas "St. Davis Street 12" will do.
I would like to get it done with regular expression as I've been using them throughout my work, but I don't mind other solutions.
I'm using Visual Studio 2010 Professional, 4.0 framework and Visual Basic.
Thanks for your time

Member Avatar for Unhnd_Exception
Private Sub ButtonInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonInput.Click

        Dim ContainsAlpha As Boolean
        Dim ContainsNumeric As Boolean
        Dim ContainsInvalidCharacter As Boolean

        'Iterate through each character and determine if its a number,
        'letter, or non number of letter.
        For Each Character As Char In TextBoxStreetAddress.Text
            If Char.IsNumber(Character) Then
                ContainsNumeric = True
            ElseIf Char.IsLetter(Character) Then
                ContainsAlpha = True
            ElseIf Not Char.IsWhiteSpace(Character) Then
                ContainsInvalidCharacter = True
                Exit For
            End If
        Next

        If ContainsInvalidCharacter Then
            'Contains a non alpha or numeric character
        ElseIf Not ContainsAlpha OrElse Not ContainsNumeric Then
            'Doesn't have at least one of each.
        End If

    End Sub

Thank you very much Unh_Exception, you sorted that out.
What I wasn't thinking of was a couple of booleans to state whether the string contains letters and numbers.
Thank you very much =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.