In my spare time i give myself programming stuff to do. Today i want to write a function that goes through a string, if the string contains any numeric value the function must return false, if the string has any special characters it must also return false else return true. For example the following strings would return as follows:

String Return Value
Travis True
78* False
44Travis False
(Travis) False

Any ideas on how to achieve this would be fine.

There are many ways to do that. Here is one:

Imports System
Imports System.Linq
''
Module Module1
   Function IsGoodString(ByVal strData As String) As Boolean
      If strData.Any(Function(c) Char.IsDigit(c) Or Char.IsPunctuation(c)) Then
         Return False
      End If

      Return True
   End Function
   Sub Main()
      Console.WriteLine(IsGoodString("Travis"))
      Console.WriteLine(IsGoodString("78*"))
      Console.WriteLine(IsGoodString("(neato)"))

   End Sub
End Module

Function StringCheck(ByVal str As String) As Boolean

    Dim staticstr As String = "^[a-zA-Z]*[a-zA-Z]$"

Dim enfstr As Match = Regex.Match(str, staticstr)

If enfstr.Success Then
return True
Else
return False
End If

End Function

NB I imported the Regular expressions namespace.

The issue I am having is that I can only prevent the users from entering numbers. Special characters giving me headache

this is the function i wrote sorry about the previous post

Function StringCheck(ByVal str As String) As Boolean

    Dim staticstr As String = "^[a-zA-Z]*[a-zA-Z]$"

    Dim enfstr As Match = Regex.Match(str, staticstr)

    If enfstr.Success Then
        Return True
    Else
        Return False
    End If

End Function
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.