VBScript function to check if value is a letter

Is there any VBScript function to check if a value is a letter, such as IsNumeric() for numbers?
Carlos_FelipeAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
Here's a slightly lighter version that just checks for upper and lower case letters.

Wscript.Echo IsAlpha("testString")
Wscript.Echo IsAlpha("test String")

Function IsAlpha(s)
   Dim r, m
   Set r = New RegExp
   r.Pattern = "^[A-Za-z]*$"
   Set m = r.Execute(s)
   If m.Count = 0 Then
      IsAlpha = False
   Else
      IsAlpha = True
   End If
   Set w = Nothing
   Set r = Nothing
End Function

Open in new window

~bp
0
 
Bill PrewCommented:
No built in function in VBS for this, but you could write a small function to do it.  Here's a simple example of using regular expressions to implement it.

http://psacake.com/web/func/isalpha_function.htm

~bp
0
 
Bill PrewCommented:
Looking at that example I think we could simplify a bit, what characters do you want to pass, just a-z and A-Z, or any others like space, etc?

~bp
0
 
Carlos_FelipeAuthor Commented:
I did something simple:

If Asc(UCase(strBranchDrive))=>65 And Asc(UCase(strBranchDrive))=< 90 Then

Thank you all for the help!
0
 
Bill PrewCommented:
Yup, that will work too, I guess I sort of assumed you were looking for something more "interesting" thank that, but glad you have a solution, and thanks for the points.

~bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.