Jason94 Jason94 - 1 year ago 74
C# Question

Regex to only match words without special symbols or numbers

I'm trying to figure out how to match "word" but not "word1", "w1ord" or any variation of "word!" where "!" could be anything "#%!"

Basically I want to match against word that only uses A-Z and a-z. The following does not work :/


As "word%5" is a match.

Answer Source
bool notOnlyLetters = yourStringValue.ToArray().Any(x => !(x >= 65 && x <= 122));

You can do it with linq

EDIT: After second correct edit of Wiktor.

bool notOnlyLetters = yourStringValue.ToUpper().ToArray().Any(x => !(x >= 65 && x <= 90));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download