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
Suzan
suzan_Asked:
Who is Participating?
 
mkosbieConnect With a Mentor Commented:
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

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

Fernando
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
suzan_Author Commented:
thanks both for the help

Fernando

? . ,  " (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
0
 
suzan_Author Commented:
thanks a lot mkosbie
this really help
0
 
mkosbieCommented:
Glad to help.
0
 
suzan_Author Commented:
mkosbie
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
suzan
0
 
mkosbieCommented:
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 (http://www.regexbuddy.com/) to help make expressions.
0
 
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
suzan
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.