Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET how can I check if String Contains alphabet characters and .?

Using visual basic, I have a string. Want to check that the string contains a single, capital alphabetic character followed by a period. Tried to use Contains as in the following:

someString.Contains("[A-Z].") but this didn't return me what I wanted.

Also need to check for a single number followed by a period.

How can I do this in Visual Basic

like image 570
user840930 Avatar asked Feb 14 '12 14:02

user840930


1 Answers

The logic is a little off in the highest rated answer. The function will only validate the first character and then return true. Here's the tweak that would validate the entire string for alpha characters:

'Validates a string of alpha characters
Function CheckForAlphaCharacters(ByVal StringToCheck As String)
    For i = 0 To StringToCheck.Length - 1
        If Not Char.IsLetter(StringToCheck.Chars(i)) Then
            Return False
        End If
    Next

    Return True 'Return true if all elements are characters
End Function
like image 119
HelloImKevo Avatar answered Sep 24 '22 20:09

HelloImKevo