Check if the word is in alphabetical letters

Posted on 2008-11-09
Last Modified: 2013-12-17
Hi all

I am hoping that someone can help me on how could I check in C# if the string is in alphabetical letters or not. For example if I have this string ( Moku????ina) or (0 ft )

Is there is a statement which could help me to do that?

And is this statement will consider the word which ends with question mark (i.e the last word in the question)

Thanks in advance for your help
Question by:suzan_
    LVL 12

    Expert Comment

    You can use regular expressions to do this.
    LVL 62

    Expert Comment

    by:Fernando Soto
    Hi suzan_;

    As jandromeda stated you can use Regular Expressions. If you can give a spec on what you want to accept as a valid string I can give a Regex pattern that will work. For example you say ? at the end is valid does that also mean a . is also valid at the end and hyphenated words?


    Author Comment

    thanks both for the help


    ? . ,  " (i.e all the punctuation) which ends the words are valid

    But the punctuations or numbers in the beginning or within the word are not valid
    thanks again for your help
    LVL 8

    Accepted Solution

    If I understand correctly, you want to make sure a given string contains all words made up of letters with an optional punctuation mark at the end of each word?  The code below will do this.  Here's some sample output:

    laksjdf? jakdsj" dkjfd.  <==== Passes validation
    ?alsdkfja asdlkfj <==== Does not pass
    asdf <=== Passes validation
        private bool ValidateString(string input)
            Regex r = new Regex("^([a-z]+[?!\"',.;:]?\\s+)*([a-z]+[?!\"',.;:]?\\s*)$", RegexOptions.IgnoreCase);
            return r.IsMatch(input);

    Open in new window


    Author Comment

    thanks a lot mkosbie
    this really help
    LVL 8

    Expert Comment

    Glad to help.

    Author Comment

    or could someone help me with this

    Regex r = new Regex("^([a-z]+[?!\"',.;:]?\\s+)*([a-z]+[?!\"',.;:]?\\s*)$", RegexOptions.IgnoreCase);

    how can I  make for example
    He's  << pass validation
    "hi  << pass validation
    (hi << pass validation
    %hi << do not pass validation
    so certain punctuation pass the validation

    thanks again for help
    LVL 8

    Expert Comment

    1) What punctuation do you want to be valid at the end of the word
    2) What punctuation do you want to be valid inside of the word
    3) What punctuation do you want to be valid at the beginning of the word

    Answer those and I'll redesign the expression accordingly.

    You might consider using RegEx buddy ( to help make expressions.

    Author Comment

    thanks for replying

    the valid punctuation

    1- beginning of the word    " ( ' -
    2- inside of the word   '  only before the last letter
                                        -  any where inside the word
    3- end of the word  ! . , : ; " ) ' ? &  -

    I really appreciate your help, thanks again

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    WMI, model #, retrieving information 10 57
    Aspnet xml 2 27
    Handling arrays 14 28
    Dynamically create stored procedure   using c# 7 15
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now