Check if string contains Letters?
Posted: Sun Jan 13, 2013 9:13 pm
I'm trying to check if a string contains letters because I need a numerical only string, anyone know how to check if it contains letters?
Sharing, Teaching and Supporting coders of all ages and levels since 2009
https://www.codenstuff.com/forum/
Dim containsLetter As Boolean
For i = 0 To s.Length - 1
If Asc(s.Substring(i, 1)) < 48 Or Asc(s.Substring(i, 1)) > 57 Then containsLetter = True
Next
If containsLetter Then MessageBox.Show("The string must contain numbers only!")
if isNumeric(StringVariable) then
...
end if
Function CheckForAlphaCharacters(ByVal StringToCheck As String)
For i = 0 To StringToCheck.Length - 1
If Char.IsLetter(StringToCheck.Chars(i)) Then
Return True
End If
Next
Return False
End Function
Dim Mystring As String = "abc123"
If CheckForAlphaCharacters(Mystring) Then
'do stuff here if it contains letters
Else
'do stuff here if it doesn't contain letters
End If