Check if the word is in alphabetical letters

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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can use regular expressions to do this.
Fernando SotoRetiredCommented:
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?

suzan_Author Commented:
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
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
suzan_Author Commented:
thanks a lot mkosbie
this really help
Glad to help.
suzan_Author Commented:
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
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.
suzan_Author Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.