• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

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?
0
Carlos_Felipe
Asked:
Carlos_Felipe
  • 4
1 Solution
 
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
 
Bill PrewCommented:
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now