VBScript function to check if value is a letter

Posted on 2011-10-20
Last Modified: 2012-05-12
Is there any VBScript function to check if a value is a letter, such as IsNumeric() for numbers?
Question by:Carlos_Felipe
    LVL 51

    Expert Comment

    by:Bill Prew
    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.

    LVL 51

    Expert Comment

    by:Bill Prew
    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?

    LVL 51

    Accepted Solution

    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
          IsAlpha = True
       End If
       Set w = Nothing
       Set r = Nothing
    End Function

    Open in new window


    Author Comment

    I did something simple:

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

    Thank you all for the help!
    LVL 51

    Expert Comment

    by:Bill Prew
    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.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now