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
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
Answered By – HelloImKevo
Answer Checked By – Pedro (BugsFixing Volunteer)