I am trying to create a function which identify only the Pure Alpha characters and ignore the Special characters.
And similar to this looking for one more function that is Pure Numeric characters ignoring the special character.
But my code is not doing what i am looking for. Your help will be much appreciated.
Here is 1 example
Public Function IsLetters(s As String) As Boolean
Dim i As Long
IsLetters = False
For i = 1 To Len(s)
If Not Mid(s, i, 1) Like "[a-zA-Z]" Then Exit Function
Next i
IsLetters = True
End Function
CodePudding user response:
No Digits vs No Letters
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns a boolean indicating whether none of the characters
' of a string are digits.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function IsNotDigits( _
ByVal SearchString As String, _
Optional ByVal IncludeNullString As Boolean = False) _
As Boolean
If Len(SearchString) > 0 Then
Dim n As Long
For n = 1 To Len(SearchString)
If Mid(SearchString, n, 1) Like "[0-9]" Then Exit Function
Next n
IsNotDigits = True
Else
If IncludeNullString Then IsNotDigits = True
End If
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose: Returns a boolean indicating whether none of the characters
' of a string are letters.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function IsNotLetters( _
ByVal SearchString As String, _
Optional ByVal IncludeNullString As Boolean = False) _
As Boolean
If Len(SearchString) > 0 Then
Dim n As Long
For n = 1 To Len(SearchString)
If Mid(SearchString, n, 1) Like "[A-Za-z]" Then Exit Function
Next n
IsNotLetters = True
Else
If IncludeNullString Then IsNotLetters = True
End If
End Function
