Saravanan
Saravanan

Reputation: 11602

Regular Expression for Letters and Spaces

I have a string variable in C# and I want to check this string contains letters or not.

I used following regular expression for evaluate this condition, but I returned false in the if statement I used.

I dont know why?

My C# Code:

 string cellValue ="Row Merging Done here";
 if (Regex.IsMatch(cellValue, @"^[a-zA-Z]+$"))
 {
     messageBox.show("Message found");
 }

How to evalute this regular expression?

Upvotes: 1

Views: 8686

Answers (3)

Casabian
Casabian

Reputation: 308

You can use:RegExr to evaluate your expression

Upvotes: -1

Andrei
Andrei

Reputation: 56716

Do you need to check whether the string contains at least one word? If so, you don't need symbols for beginning and end:

if (Regex.IsMatch(cellValue, @"[a-zA-Z]+"))

Upvotes: 3

faester
faester

Reputation: 15086

Don't you need to recognize spaces: @"^[a-zA-Z ]+$"

Upvotes: 12

Related Questions